home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / man / cat.1 / flexdoc.1 < prev    next >
Text File  |  1995-07-25  |  133KB  |  2,839 lines

  1.  
  2.  
  3.  
  4.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.           flexdoc - documentation for flex, fast lexical analyzer
  10.           generator
  11.  
  12.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  13.           fffflllleeeexxxx [[[[----bbbbccccddddffffhhhhiiiillllnnnnppppssssttttvvvvwwwwBBBBFFFFIIIILLLLTTTTVVVV77778888++++ ----CCCC[[[[aaaaeeeeffffFFFFmmmmrrrr]]]] ----PPPPpppprrrreeeeffffiiiixxxx
  14.           ----SSSSsssskkkkeeeelllleeeettttoooonnnn]]]] [_f_i_l_e_n_a_m_e ...]
  15.  
  16.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  17.           _f_l_e_x is a tool for generating _s_c_a_n_n_e_r_s: programs which
  18.           recognized lexical patterns in text.  _f_l_e_x reads the given
  19.           input files, or its standard input if no file names are
  20.           given, for a description of a scanner to generate.  The
  21.           description is in the form of pairs of regular expressions
  22.           and C code, called _r_u_l_e_s. _f_l_e_x generates as output a C
  23.           source file, lllleeeexxxx....yyyyyyyy....cccc,,,, which defines a routine yyyyyyyylllleeeexxxx(((()))).... This
  24.           file is compiled and linked with the ----llllffffllll library to produce
  25.           an executable.  When the executable is run, it analyzes its
  26.           input for occurrences of the regular expressions.  Whenever
  27.           it finds one, it executes the corresponding C code.
  28.  
  29.      SSSSOOOOMMMMEEEE SSSSIIIIMMMMPPPPLLLLEEEE EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
  30.           First some simple examples to get the flavor of how one uses
  31.           _f_l_e_x. The following _f_l_e_x input specifies a scanner which
  32.           whenever it encounters the string "username" will replace it
  33.           with the user's login name:
  34.  
  35.               %%
  36.               username    printf( "%s", getlogin() );
  37.  
  38.           By default, any text not matched by a _f_l_e_x scanner is copied
  39.           to the output, so the net effect of this scanner is to copy
  40.           its input file to its output with each occurrence of
  41.           "username" expanded.  In this input, there is just one rule.
  42.           "username" is the _p_a_t_t_e_r_n and the "printf" is the _a_c_t_i_o_n.
  43.           The "%%" marks the beginning of the rules.
  44.  
  45.           Here's another simple example:
  46.  
  47.                       int num_lines = 0, num_chars = 0;
  48.  
  49.               %%
  50.               \n      ++num_lines; ++num_chars;
  51.               .       ++num_chars;
  52.  
  53.               %%
  54.               main()
  55.                       {
  56.                       yylex();
  57.                       printf( "# of lines = %d, # of chars = %d\n",
  58.                               num_lines, num_chars );
  59.                       }
  60.  
  61.  
  62.  
  63.      Page 1                                          (printed 3/28/94)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  71.  
  72.  
  73.  
  74.           This scanner counts the number of characters and the number
  75.           of lines in its input (it produces no output other than the
  76.           final report on the counts).  The first line declares two
  77.           globals, "num_lines" and "num_chars", which are accessible
  78.           both inside yyyyyyyylllleeeexxxx(((()))) and in the mmmmaaaaiiiinnnn(((()))) routine declared after
  79.           the second "%%".  There are two rules, one which matches a
  80.           newline ("\n") and increments both the line count and the
  81.           character count, and one which matches any character other
  82.           than a newline (indicated by the "." regular expression).
  83.  
  84.           A somewhat more complicated example:
  85.  
  86.               /* scanner for a toy Pascal-like language */
  87.  
  88.               %{
  89.               /* need this for the call to atof() below */
  90.               #include <math.h>
  91.               %}
  92.  
  93.               DIGIT    [0-9]
  94.               ID       [a-z][a-z0-9]*
  95.  
  96.               %%
  97.  
  98.               {DIGIT}+    {
  99.                           printf( "An integer: %s (%d)\n", yytext,
  100.                                   atoi( yytext ) );
  101.                           }
  102.  
  103.               {DIGIT}+"."{DIGIT}*        {
  104.                           printf( "A float: %s (%g)\n", yytext,
  105.                                   atof( yytext ) );
  106.                           }
  107.  
  108.               if|then|begin|end|procedure|function        {
  109.                           printf( "A keyword: %s\n", yytext );
  110.                           }
  111.  
  112.               {ID}        printf( "An identifier: %s\n", yytext );
  113.  
  114.               "+"|"-"|"*"|"/"   printf( "An operator: %s\n", yytext );
  115.  
  116.               "{"[^}\n]*"}"     /* eat up one-line comments */
  117.  
  118.               [ \t\n]+          /* eat up whitespace */
  119.  
  120.               .           printf( "Unrecognized character: %s\n", yytext );
  121.  
  122.               %%
  123.  
  124.               main( argc, argv )
  125.               int argc;
  126.  
  127.  
  128.  
  129.      Page 2                                          (printed 3/28/94)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  137.  
  138.  
  139.  
  140.               char **argv;
  141.                   {
  142.                   ++argv, --argc;  /* skip over program name */
  143.                   if ( argc > 0 )
  144.                           yyin = fopen( argv[0], "r" );
  145.                   else
  146.                           yyin = stdin;
  147.  
  148.                   yylex();
  149.                   }
  150.  
  151.           This is the beginnings of a simple scanner for a language
  152.           like Pascal.  It identifies different types of _t_o_k_e_n_s and
  153.           reports on what it has seen.
  154.  
  155.           The details of this example will be explained in the
  156.           following sections.
  157.  
  158.      FFFFOOOORRRRMMMMAAAATTTT OOOOFFFF TTTTHHHHEEEE IIIINNNNPPPPUUUUTTTT FFFFIIIILLLLEEEE
  159.           The _f_l_e_x input file consists of three sections, separated by
  160.           a line with just %%%%%%%% in it:
  161.  
  162.               definitions
  163.               %%
  164.               rules
  165.               %%
  166.               user code
  167.  
  168.           The _d_e_f_i_n_i_t_i_o_n_s section contains declarations of simple _n_a_m_e
  169.           definitions to simplify the scanner specification, and
  170.           declarations of _s_t_a_r_t _c_o_n_d_i_t_i_o_n_s, which are explained in a
  171.           later section.
  172.  
  173.           Name definitions have the form:
  174.  
  175.               name definition
  176.  
  177.           The "name" is a word beginning with a letter or an
  178.           underscore ('_') followed by zero or more letters, digits,
  179.           '_', or '-' (dash).  The definition is taken to begin at the
  180.           first non-white-space character following the name and
  181.           continuing to the end of the line.  The definition can
  182.           subsequently be referred to using "{name}", which will
  183.           expand to "(definition)".  For example,
  184.  
  185.               DIGIT    [0-9]
  186.               ID       [a-z][a-z0-9]*
  187.  
  188.           defines "DIGIT" to be a regular expression which matches a
  189.           single digit, and "ID" to be a regular expression which
  190.           matches a letter followed by zero-or-more letters-or-digits.
  191.           A subsequent reference to
  192.  
  193.  
  194.  
  195.      Page 3                                          (printed 3/28/94)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  203.  
  204.  
  205.  
  206.               {DIGIT}+"."{DIGIT}*
  207.  
  208.           is identical to
  209.  
  210.               ([0-9])+"."([0-9])*
  211.  
  212.           and matches one-or-more digits followed by a '.' followed by
  213.           zero-or-more digits.
  214.  
  215.           The _r_u_l_e_s section of the _f_l_e_x input contains a series of
  216.           rules of the form:
  217.  
  218.               pattern   action
  219.  
  220.           where the pattern must be unindented and the action must
  221.           begin on the same line.
  222.  
  223.           See below for a further description of patterns and actions.
  224.  
  225.           Finally, the user code section is simply copied to lllleeeexxxx....yyyyyyyy....cccc
  226.           verbatim.  It is used for companion routines which call or
  227.           are called by the scanner.  The presence of this section is
  228.           optional; if it is missing, the second %%%%%%%% in the input file
  229.           may be skipped, too.
  230.  
  231.           In the definitions and rules sections, any _i_n_d_e_n_t_e_d text or
  232.           text enclosed in %%%%{{{{ and %%%%}}}} is copied verbatim to the output
  233.           (with the %{}'s removed).  The %{}'s must appear unindented
  234.           on lines by themselves.
  235.  
  236.           In the rules section, any indented or %{} text appearing
  237.           before the first rule may be used to declare variables which
  238.           are local to the scanning routine and (after the
  239.           declarations) code which is to be executed whenever the
  240.           scanning routine is entered.  Other indented or %{} text in
  241.           the rule section is still copied to the output, but its
  242.           meaning is not well-defined and it may well cause compile-
  243.           time errors (this feature is present for _P_O_S_I_X compliance;
  244.           see below for other such features).
  245.  
  246.           In the definitions section (but not in the rules section),
  247.           an unindented comment (i.e., a line beginning with "/*") is
  248.           also copied verbatim to the output up to the next "*/".
  249.  
  250.      PPPPAAAATTTTTTTTEEEERRRRNNNNSSSS
  251.           The patterns in the input are written using an extended set
  252.           of regular expressions.  These are:
  253.  
  254.               x          match the character 'x'
  255.               .          any character except newline
  256.               [xyz]      a "character class"; in this case, the pattern
  257.                            matches either an 'x', a 'y', or a 'z'
  258.  
  259.  
  260.  
  261.      Page 4                                          (printed 3/28/94)
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  269.  
  270.  
  271.  
  272.               [abj-oZ]   a "character class" with a range in it; matches
  273.                            an 'a', a 'b', any letter from 'j' through 'o',
  274.                            or a 'Z'
  275.               [^A-Z]     a "negated character class", i.e., any character
  276.                            but those in the class.  In this case, any
  277.                            character EXCEPT an uppercase letter.
  278.               [^A-Z\n]   any character EXCEPT an uppercase letter or
  279.                            a newline
  280.               r*         zero or more r's, where r is any regular expression
  281.               r+         one or more r's
  282.               r?         zero or one r's (that is, "an optional r")
  283.               r{2,5}     anywhere from two to five r's
  284.               r{2,}      two or more r's
  285.               r{4}       exactly 4 r's
  286.               {name}     the expansion of the "name" definition
  287.                          (see above)
  288.               "[xyz]\"foo"
  289.                          the literal string: [xyz]"foo
  290.               \X         if X is an 'a', 'b', 'f', 'n', 'r', 't', or 'v',
  291.                            then the ANSI-C interpretation of \x.
  292.                            Otherwise, a literal 'X' (used to escape
  293.                            operators such as '*')
  294.               \123       the character with octal value 123
  295.               \x2a       the character with hexadecimal value 2a
  296.               (r)        match an r; parentheses are used to override
  297.                            precedence (see below)
  298.  
  299.  
  300.               rs         the regular expression r followed by the
  301.                            regular expression s; called "concatenation"
  302.  
  303.  
  304.               r|s        either an r or an s
  305.  
  306.  
  307.               r/s        an r but only if it is followed by an s.  The
  308.                            s is not part of the matched text.  This type
  309.                            of pattern is called as "trailing context".
  310.               ^r         an r, but only at the beginning of a line
  311.               r$         an r, but only at the end of a line.  Equivalent
  312.                            to "r/\n".
  313.  
  314.  
  315.               <s>r       an r, but only in start condition s (see
  316.                          below for discussion of start conditions)
  317.               <s1,s2,s3>r
  318.                          same, but in any of start conditions s1,
  319.                          s2, or s3
  320.               <*>r       an r in any start condition, even an exclusive one.
  321.  
  322.  
  323.               <<EOF>>    an end-of-file
  324.  
  325.  
  326.  
  327.      Page 5                                          (printed 3/28/94)
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  335.  
  336.  
  337.  
  338.               <s1,s2><<EOF>>
  339.                          an end-of-file when in start condition s1 or s2
  340.  
  341.           Note that inside of a character class, all regular
  342.           expression operators lose their special meaning except
  343.           escape ('\') and the character class operators, '-', ']',
  344.           and, at the beginning of the class, '^'.
  345.  
  346.           The regular expressions listed above are grouped according
  347.           to precedence, from highest precedence at the top to lowest
  348.           at the bottom.  Those grouped together have equal
  349.           precedence.  For example,
  350.  
  351.               foo|bar*
  352.  
  353.           is the same as
  354.  
  355.               (foo)|(ba(r*))
  356.  
  357.           since the '*' operator has higher precedence than
  358.           concatenation, and concatenation higher than alternation
  359.           ('|').  This pattern therefore matches _e_i_t_h_e_r the string
  360.           "foo" _o_r the string "ba" followed by zero-or-more r's.  To
  361.           match "foo" or zero-or-more "bar"'s, use:
  362.  
  363.               foo|(bar)*
  364.  
  365.           and to match zero-or-more "foo"'s-or-"bar"'s:
  366.  
  367.               (foo|bar)*
  368.  
  369.  
  370.           Some notes on patterns:
  371.  
  372.           -    A negated character class such as the example "[^A-Z]"
  373.                above _w_i_l_l _m_a_t_c_h _a _n_e_w_l_i_n_e unless "\n" (or an
  374.                equivalent escape sequence) is one of the characters
  375.                explicitly present in the negated character class
  376.                (e.g., "[^A-Z\n]").  This is unlike how many other
  377.                regular expression tools treat negated character
  378.                classes, but unfortunately the inconsistency is
  379.                historically entrenched.  Matching newlines means that
  380.                a pattern like [^"]* can match the entire input unless
  381.                there's another quote in the input.
  382.  
  383.           -    A rule can have at most one instance of trailing
  384.                context (the '/' operator or the '$' operator).  The
  385.                start condition, '^', and "<<EOF>>" patterns can only
  386.                occur at the beginning of a pattern, and, as well as
  387.                with '/' and '$', cannot be grouped inside parentheses.
  388.                A '^' which does not occur at the beginning of a rule
  389.                or a '$' which does not occur at the end of a rule
  390.  
  391.  
  392.  
  393.      Page 6                                          (printed 3/28/94)
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  401.  
  402.  
  403.  
  404.                loses its special properties and is treated as a normal
  405.                character.
  406.  
  407.                The following are illegal:
  408.  
  409.                    foo/bar$
  410.                    <sc1>foo<sc2>bar
  411.  
  412.                Note that the first of these, can be written
  413.                "foo/bar\n".
  414.  
  415.                The following will result in '$' or '^' being treated
  416.                as a normal character:
  417.  
  418.                    foo|(bar$)
  419.                    foo|^bar
  420.  
  421.                If what's wanted is a "foo" or a bar-followed-by-a-
  422.                newline, the following could be used (the special '|'
  423.                action is explained below):
  424.  
  425.                    foo      |
  426.                    bar$     /* action goes here */
  427.  
  428.                A similar trick will work for matching a foo or a bar-
  429.                at-the-beginning-of-a-line.
  430.  
  431.      HHHHOOOOWWWW TTTTHHHHEEEE IIIINNNNPPPPUUUUTTTT IIIISSSS MMMMAAAATTTTCCCCHHHHEEEEDDDD
  432.           When the generated scanner is run, it analyzes its input
  433.           looking for strings which match any of its patterns.  If it
  434.           finds more than one match, it takes the one matching the
  435.           most text (for trailing context rules, this includes the
  436.           length of the trailing part, even though it will then be
  437.           returned to the input).  If it finds two or more matches of
  438.           the same length, the rule listed first in the _f_l_e_x input
  439.           file is chosen.
  440.  
  441.           Once the match is determined, the text corresponding to the
  442.           match (called the _t_o_k_e_n) is made available in the global
  443.           character pointer yyyyyyyytttteeeexxxxtttt,,,, and its length in the global
  444.           integer yyyyyyyylllleeeennnngggg.... The _a_c_t_i_o_n corresponding to the matched
  445.           pattern is then executed (a more detailed description of
  446.           actions follows), and then the remaining input is scanned
  447.           for another match.
  448.  
  449.           If no match is found, then the _d_e_f_a_u_l_t _r_u_l_e is executed: the
  450.           next character in the input is considered matched and copied
  451.           to the standard output.  Thus, the simplest legal _f_l_e_x input
  452.           is:
  453.  
  454.               %%
  455.  
  456.  
  457.  
  458.  
  459.      Page 7                                          (printed 3/28/94)
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  467.  
  468.  
  469.  
  470.           which generates a scanner that simply copies its input (one
  471.           character at a time) to its output.
  472.  
  473.           Note that yyyyyyyytttteeeexxxxtttt can be defined in two different ways:
  474.           either as a character _p_o_i_n_t_e_r or as a character _a_r_r_a_y. You
  475.           can control which definition _f_l_e_x uses by including one of
  476.           the special directives %%%%ppppooooiiiinnnntttteeeerrrr or %%%%aaaarrrrrrrraaaayyyy in the first
  477.           (definitions) section of your flex input.  The default is
  478.           %%%%ppppooooiiiinnnntttteeeerrrr,,,, unless you use the ----llll lex compatibility option, in
  479.           which case yyyyyyyytttteeeexxxxtttt will be an array.  The advantage of using
  480.           %%%%ppppooooiiiinnnntttteeeerrrr is substantially faster scanning and no buffer
  481.           overflow when matching very large tokens (unless you run out
  482.           of dynamic memory).  The disadvantage is that you are
  483.           restricted in how your actions can modify yyyyyyyytttteeeexxxxtttt (see the
  484.           next section), and calls to the iiiinnnnppppuuuutttt(((()))) and uuuunnnnppppuuuutttt(((())))
  485.           functions destroy the present contents of yyyyyyyytttteeeexxxxtttt,,,, which can
  486.           be a considerable porting headache when moving between
  487.           different _l_e_x versions.
  488.  
  489.           The advantage of %%%%aaaarrrrrrrraaaayyyy is that you can then modify yyyyyyyytttteeeexxxxtttt
  490.           to your heart's content, and calls to iiiinnnnppppuuuutttt(((()))) and uuuunnnnppppuuuutttt(((()))) do
  491.           not destroy yyyyyyyytttteeeexxxxtttt (see below).  Furthermore, existing _l_e_x
  492.           programs sometimes access yyyyyyyytttteeeexxxxtttt externally using
  493.           declarations of the form:
  494.               extern char yytext[];
  495.           This definition is erroneous when used with %%%%ppppooooiiiinnnntttteeeerrrr,,,, but
  496.           correct for %%%%aaaarrrrrrrraaaayyyy....
  497.  
  498.           %%%%aaaarrrrrrrraaaayyyy defines yyyyyyyytttteeeexxxxtttt to be an array of YYYYYYYYLLLLMMMMAAAAXXXX characters,
  499.           which defaults to a fairly large value.  You can change the
  500.           size by simply #define'ing YYYYYYYYLLLLMMMMAAAAXXXX to a different value in
  501.           the first section of your _f_l_e_x input.  As mentioned above,
  502.           with %%%%ppppooooiiiinnnntttteeeerrrr yytext grows dynamically to accomodate large
  503.           tokens.  While this means your %%%%ppppooooiiiinnnntttteeeerrrr scanner can
  504.           accomodate very large tokens (such as matching entire blocks
  505.           of comments), bear in mind that each time the scanner must
  506.           resize yyyyyyyytttteeeexxxxtttt it also must rescan the entire token from the
  507.           beginning, so matching such tokens can prove slow.  yyyyyyyytttteeeexxxxtttt
  508.           presently does _n_o_t dynamically grow if a call to uuuunnnnppppuuuutttt(((())))
  509.           results in too much text being pushed back; instead, a run-
  510.           time error results.
  511.  
  512.           Also note that you cannot use %%%%aaaarrrrrrrraaaayyyy with C++ scanner
  513.           classes (the ----++++ option; see below).
  514.  
  515.      AAAACCCCTTTTIIIIOOOONNNNSSSS
  516.           Each pattern in a rule has a corresponding action, which can
  517.           be any arbitrary C statement.  The pattern ends at the first
  518.           non-escaped whitespace character; the remainder of the line
  519.           is its action.  If the action is empty, then when the
  520.           pattern is matched the input token is simply discarded.  For
  521.           example, here is the specification for a program which
  522.  
  523.  
  524.  
  525.      Page 8                                          (printed 3/28/94)
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  533.  
  534.  
  535.  
  536.           deletes all occurrences of "zap me" from its input:
  537.  
  538.               %%
  539.               "zap me"
  540.  
  541.           (It will copy all other characters in the input to the
  542.           output since they will be matched by the default rule.)
  543.  
  544.           Here is a program which compresses multiple blanks and tabs
  545.           down to a single blank, and throws away whitespace found at
  546.           the end of a line:
  547.  
  548.               %%
  549.               [ \t]+        putchar( ' ' );
  550.               [ \t]+$       /* ignore this token */
  551.  
  552.  
  553.           If the action contains a '{', then the action spans till the
  554.           balancing '}' is found, and the action may cross multiple
  555.           lines.  _f_l_e_x knows about C strings and comments and won't be
  556.           fooled by braces found within them, but also allows actions
  557.           to begin with %%%%{{{{ and will consider the action to be all the
  558.           text up to the next %%%%}}}} (regardless of ordinary braces inside
  559.           the action).
  560.  
  561.           An action consisting solely of a vertical bar ('|') means
  562.           "same as the action for the next rule."  See below for an
  563.           illustration.
  564.  
  565.           Actions can include arbitrary C code, including rrrreeeettttuuuurrrrnnnn
  566.           statements to return a value to whatever routine called
  567.           yyyyyyyylllleeeexxxx(((()))).... Each time yyyyyyyylllleeeexxxx(((()))) is called it continues processing
  568.           tokens from where it last left off until it either reaches
  569.           the end of the file or executes a return.
  570.  
  571.           Actions are free to modify yyyyyyyytttteeeexxxxtttt except for lengthening it
  572.           (adding characters to its end--these will overwrite later
  573.           characters in the input stream).  Modifying the final
  574.           character of yytext may alter whether when scanning resumes
  575.           rules anchored with '^' are active.  Specifically, changing
  576.           the final character of yytext to a newline will activate
  577.           such rules on the next scan, and changing it to anything
  578.           else will deactivate the rules.  Users should not rely on
  579.           this behavior being present in future releases.  Finally,
  580.           note that none of this paragraph applies when using %%%%aaaarrrrrrrraaaayyyy
  581.           (see above).
  582.  
  583.           Actions are free to modify yyyyyyyylllleeeennnngggg except they should not do
  584.           so if the action also includes use of yyyyyyyymmmmoooorrrreeee(((()))) (see below).
  585.  
  586.           There are a number of special directives which can be
  587.           included within an action:
  588.  
  589.  
  590.  
  591.      Page 9                                          (printed 3/28/94)
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  599.  
  600.  
  601.  
  602.           -    EEEECCCCHHHHOOOO copies yytext to the scanner's output.
  603.  
  604.           -    BBBBEEEEGGGGIIIINNNN followed by the name of a start condition places
  605.                the scanner in the corresponding start condition (see
  606.                below).
  607.  
  608.           -    RRRREEEEJJJJEEEECCCCTTTT directs the scanner to proceed on to the "second
  609.                best" rule which matched the input (or a prefix of the
  610.                input).  The rule is chosen as described above in "How
  611.                the Input is Matched", and yyyyyyyytttteeeexxxxtttt and yyyyyyyylllleeeennnngggg set up
  612.                appropriately.  It may either be one which matched as
  613.                much text as the originally chosen rule but came later
  614.                in the _f_l_e_x input file, or one which matched less text.
  615.                For example, the following will both count the words in
  616.                the input and call the routine special() whenever
  617.                "frob" is seen:
  618.  
  619.                            int word_count = 0;
  620.                    %%
  621.  
  622.                    frob        special(); REJECT;
  623.                    [^ \t\n]+   ++word_count;
  624.  
  625.                Without the RRRREEEEJJJJEEEECCCCTTTT,,,, any "frob"'s in the input would not
  626.                be counted as words, since the scanner normally
  627.                executes only one action per token.  Multiple RRRREEEEJJJJEEEECCCCTTTT''''ssss
  628.                are allowed, each one finding the next best choice to
  629.                the currently active rule.  For example, when the
  630.                following scanner scans the token "abcd", it will write
  631.                "abcdabcaba" to the output:
  632.  
  633.                    %%
  634.                    a        |
  635.                    ab       |
  636.                    abc      |
  637.                    abcd     ECHO; REJECT;
  638.                    .|\n     /* eat up any unmatched character */
  639.  
  640.                (The first three rules share the fourth's action since
  641.                they use the special '|' action.) RRRREEEEJJJJEEEECCCCTTTT is a
  642.                particularly expensive feature in terms scanner
  643.                performance; if it is used in _a_n_y of the scanner's
  644.                actions it will slow down _a_l_l of the scanner's
  645.                matching.  Furthermore, RRRREEEEJJJJEEEECCCCTTTT cannot be used with the
  646.                -_C_f or -_C_F options (see below).
  647.  
  648.                Note also that unlike the other special actions, RRRREEEEJJJJEEEECCCCTTTT
  649.                is a _b_r_a_n_c_h; code immediately following it in the
  650.                action will _n_o_t be executed.
  651.  
  652.           -    yyyyyyyymmmmoooorrrreeee(((()))) tells the scanner that the next time it
  653.                matches a rule, the corresponding token should be
  654.  
  655.  
  656.  
  657.      Page 10                                         (printed 3/28/94)
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  665.  
  666.  
  667.  
  668.                _a_p_p_e_n_d_e_d onto the current value of yyyyyyyytttteeeexxxxtttt rather than
  669.                replacing it.  For example, given the input "mega-
  670.                kludge" the following will write "mega-mega-kludge" to
  671.                the output:
  672.  
  673.                    %%
  674.                    mega-    ECHO; yymore();
  675.                    kludge   ECHO;
  676.  
  677.                First "mega-" is matched and echoed to the output.
  678.                Then "kludge" is matched, but the previous "mega-" is
  679.                still hanging around at the beginning of yyyyyyyytttteeeexxxxtttt so the
  680.                EEEECCCCHHHHOOOO for the "kludge" rule will actually write "mega-
  681.                kludge".  The presence of yyyyyyyymmmmoooorrrreeee(((()))) in the scanner's
  682.                action entails a minor performance penalty in the
  683.                scanner's matching speed.
  684.  
  685.           -    yyyyyyyylllleeeessssssss((((nnnn)))) returns all but the first _n characters of the
  686.                current token back to the input stream, where they will
  687.                be rescanned when the scanner looks for the next match.
  688.                yyyyyyyytttteeeexxxxtttt and yyyyyyyylllleeeennnngggg are adjusted appropriately (e.g.,
  689.                yyyyyyyylllleeeennnngggg will now be equal to _n ).  For example, on the
  690.                input "foobar" the following will write out
  691.                "foobarbar":
  692.  
  693.                    %%
  694.                    foobar    ECHO; yyless(3);
  695.                    [a-z]+    ECHO;
  696.  
  697.                An argument of 0 to yyyyyyyylllleeeessssssss will cause the entire
  698.                current input string to be scanned again.  Unless
  699.                you've changed how the scanner will subsequently
  700.                process its input (using BBBBEEEEGGGGIIIINNNN,,,, for example), this will
  701.                result in an endless loop.
  702.  
  703.           Note that yyyyyyyylllleeeessssssss is a macro and can only be used in the flex
  704.           input file, not from other source files.
  705.  
  706.           -    uuuunnnnppppuuuutttt((((cccc)))) puts the character _c back onto the input
  707.                stream.  It will be the next character scanned.  The
  708.                following action will take the current token and cause
  709.                it to be rescanned enclosed in parentheses.
  710.  
  711.                    {
  712.                    int i;
  713.                    unput( ')' );
  714.                    for ( i = yyleng - 1; i >= 0; --i )
  715.                        unput( yytext[i] );
  716.                    unput( '(' );
  717.                    }
  718.  
  719.                Note that since each uuuunnnnppppuuuutttt(((()))) puts the given character
  720.  
  721.  
  722.  
  723.      Page 11                                         (printed 3/28/94)
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  731.  
  732.  
  733.  
  734.                back at the _b_e_g_i_n_n_i_n_g of the input stream, pushing back
  735.                strings must be done back-to-front.  Also note that you
  736.                cannot put back EEEEOOOOFFFF to attempt to mark the input stream
  737.                with an end-of-file.
  738.  
  739.           -    iiiinnnnppppuuuutttt(((()))) reads the next character from the input stream.
  740.                For example, the following is one way to eat up C
  741.                comments:
  742.  
  743.                    %%
  744.                    "/*"        {
  745.                                register int c;
  746.  
  747.                                for ( ; ; )
  748.                                    {
  749.                                    while ( (c = input()) != '*' &&
  750.                                            c != EOF )
  751.                                        ;    /* eat up text of comment */
  752.  
  753.                                    if ( c == '*' )
  754.                                        {
  755.                                        while ( (c = input()) == '*' )
  756.                                            ;
  757.                                        if ( c == '/' )
  758.                                            break;    /* found the end */
  759.                                        }
  760.  
  761.                                    if ( c == EOF )
  762.                                        {
  763.                                        error( "EOF in comment" );
  764.                                        break;
  765.                                        }
  766.                                    }
  767.                                }
  768.  
  769.                (Note that if the scanner is compiled using CCCC++++++++,,,, then
  770.                iiiinnnnppppuuuutttt(((()))) is instead referred to as yyyyyyyyiiiinnnnppppuuuutttt(((()))),,,, in order
  771.                to avoid a name clash with the CCCC++++++++ stream by the name
  772.                of _i_n_p_u_t.)
  773.  
  774.           -    yyyyyyyytttteeeerrrrmmmmiiiinnnnaaaatttteeee(((()))) can be used in lieu of a return statement
  775.                in an action.  It terminates the scanner and returns a
  776.                0 to the scanner's caller, indicating "all done".  By
  777.                default, yyyyyyyytttteeeerrrrmmmmiiiinnnnaaaatttteeee(((()))) is also called when an end-of-
  778.                file is encountered.  It is a macro and may be
  779.                redefined.
  780.  
  781.      TTTTHHHHEEEE GGGGEEEENNNNEEEERRRRAAAATTTTEEEEDDDD SSSSCCCCAAAANNNNNNNNEEEERRRR
  782.           The output of _f_l_e_x is the file lllleeeexxxx....yyyyyyyy....cccc,,,, which contains the
  783.           scanning routine yyyyyyyylllleeeexxxx(((()))),,,, a number of tables used by it for
  784.           matching tokens, and a number of auxiliary routines and
  785.           macros.  By default, yyyyyyyylllleeeexxxx(((()))) is declared as follows:
  786.  
  787.  
  788.  
  789.      Page 12                                         (printed 3/28/94)
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  797.  
  798.  
  799.  
  800.               int yylex()
  801.                   {
  802.                   ... various definitions and the actions in here ...
  803.                   }
  804.  
  805.           (If your environment supports function prototypes, then it
  806.           will be "int yylex( void )".)  This definition may be
  807.           changed by defining the "YY_DECL" macro.  For example, you
  808.           could use:
  809.  
  810.               #define YY_DECL float lexscan( a, b ) float a, b;
  811.  
  812.           to give the scanning routine the name _l_e_x_s_c_a_n, returning a
  813.           float, and taking two floats as arguments.  Note that if you
  814.           give arguments to the scanning routine using a K&R-
  815.           style/non-prototyped function declaration, you must
  816.           terminate the definition with a semi-colon (;).
  817.  
  818.           Whenever yyyyyyyylllleeeexxxx(((()))) is called, it scans tokens from the global
  819.           input file _y_y_i_n (which defaults to stdin).  It continues
  820.           until it either reaches an end-of-file (at which point it
  821.           returns the value 0) or one of its actions executes a _r_e_t_u_r_n
  822.           statement.
  823.  
  824.           If the scanner reaches an end-of-file, subsequent calls are
  825.           undefined unless either _y_y_i_n is pointed at a new input file
  826.           (in which case scanning continues from that file), or
  827.           yyyyyyyyrrrreeeessssttttaaaarrrrtttt(((()))) is called.  yyyyyyyyrrrreeeessssttttaaaarrrrtttt(((()))) takes one argument, a
  828.           FFFFIIIILLLLEEEE **** pointer, and initializes _y_y_i_n for scanning from that
  829.           file.  Essentially there is no difference between just
  830.           assigning _y_y_i_n to a new input file or using yyyyyyyyrrrreeeessssttttaaaarrrrtttt(((()))) to
  831.           do so; the latter is available for compatibility with
  832.           previous versions of _f_l_e_x, and because it can be used to
  833.           switch input files in the middle of scanning.  It can also
  834.           be used to throw away the current input buffer, by calling
  835.           it with an argument of _y_y_i_n.
  836.  
  837.           If yyyyyyyylllleeeexxxx(((()))) stops scanning due to executing a _r_e_t_u_r_n
  838.           statement in one of the actions, the scanner may then be
  839.           called again and it will resume scanning where it left off.
  840.  
  841.           By default (and for purposes of efficiency), the scanner
  842.           uses block-reads rather than simple _g_e_t_c() calls to read
  843.           characters from _y_y_i_n. The nature of how it gets its input
  844.           can be controlled by defining the YYYYYYYY____IIIINNNNPPPPUUUUTTTT macro.
  845.           YY_INPUT's calling sequence is
  846.           "YY_INPUT(buf,result,max_size)".  Its action is to place up
  847.           to _m_a_x__s_i_z_e characters in the character array _b_u_f and return
  848.           in the integer variable _r_e_s_u_l_t either the number of
  849.           characters read or the constant YY_NULL (0 on Unix systems)
  850.           to indicate EOF.  The default YY_INPUT reads from the global
  851.           file-pointer "yyin".
  852.  
  853.  
  854.  
  855.      Page 13                                         (printed 3/28/94)
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  863.  
  864.  
  865.  
  866.           A sample definition of YY_INPUT (in the definitions section
  867.           of the input file):
  868.  
  869.               %{
  870.               #define YY_INPUT(buf,result,max_size) \
  871.                   { \
  872.                   int c = getchar(); \
  873.                   result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \
  874.                   }
  875.               %}
  876.  
  877.           This definition will change the input processing to occur
  878.           one character at a time.
  879.  
  880.           You also can add in things like keeping track of the input
  881.           line number this way; but don't expect your scanner to go
  882.           very fast.
  883.  
  884.           When the scanner receives an end-of-file indication from
  885.           YY_INPUT, it then checks the yyyyyyyywwwwrrrraaaapppp(((()))) function.  If yyyyyyyywwwwrrrraaaapppp(((())))
  886.           returns false (zero), then it is assumed that the function
  887.           has gone ahead and set up _y_y_i_n to point to another input
  888.           file, and scanning continues.  If it returns true (non-
  889.           zero), then the scanner terminates, returning 0 to its
  890.           caller.
  891.  
  892.           The default yyyyyyyywwwwrrrraaaapppp(((()))) always returns 1.
  893.  
  894.           The scanner writes its EEEECCCCHHHHOOOO output to the _y_y_o_u_t global
  895.           (default, stdout), which may be redefined by the user simply
  896.           by assigning it to some other FFFFIIIILLLLEEEE pointer.
  897.  
  898.      SSSSTTTTAAAARRRRTTTT CCCCOOOONNNNDDDDIIIITTTTIIIIOOOONNNNSSSS
  899.           _f_l_e_x provides a mechanism for conditionally activating
  900.           rules.  Any rule whose pattern is prefixed with "<sc>" will
  901.           only be active when the scanner is in the start condition
  902.           named "sc".  For example,
  903.  
  904.               <STRING>[^"]*        { /* eat up the string body ... */
  905.                           ...
  906.                           }
  907.  
  908.           will be active only when the scanner is in the "STRING"
  909.           start condition, and
  910.  
  911.               <INITIAL,STRING,QUOTE>\.        { /* handle an escape ... */
  912.                           ...
  913.                           }
  914.  
  915.           will be active only when the current start condition is
  916.           either "INITIAL", "STRING", or "QUOTE".
  917.  
  918.  
  919.  
  920.  
  921.      Page 14                                         (printed 3/28/94)
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  929.  
  930.  
  931.  
  932.           Start conditions are declared in the definitions (first)
  933.           section of the input using unindented lines beginning with
  934.           either %%%%ssss or %%%%xxxx followed by a list of names.  The former
  935.           declares _i_n_c_l_u_s_i_v_e start conditions, the latter _e_x_c_l_u_s_i_v_e
  936.           start conditions.  A start condition is activated using the
  937.           BBBBEEEEGGGGIIIINNNN action.  Until the next BBBBEEEEGGGGIIIINNNN action is executed,
  938.           rules with the given start condition will be active and
  939.           rules with other start conditions will be inactive.  If the
  940.           start condition is _i_n_c_l_u_s_i_v_e, then rules with no start
  941.           conditions at all will also be active.  If it is _e_x_c_l_u_s_i_v_e,
  942.           then _o_n_l_y rules qualified with the start condition will be
  943.           active.  A set of rules contingent on the same exclusive
  944.           start condition describe a scanner which is independent of
  945.           any of the other rules in the _f_l_e_x input.  Because of this,
  946.           exclusive start conditions make it easy to specify "mini-
  947.           scanners" which scan portions of the input that are
  948.           syntactically different from the rest (e.g., comments).
  949.  
  950.           If the distinction between inclusive and exclusive start
  951.           conditions is still a little vague, here's a simple example
  952.           illustrating the connection between the two.  The set of
  953.           rules:
  954.  
  955.               %s example
  956.               %%
  957.               <example>foo           /* do something */
  958.  
  959.           is equivalent to
  960.  
  961.               %x example
  962.               %%
  963.               <INITIAL,example>foo   /* do something */
  964.  
  965.  
  966.           Also note that the special start-condition specifier <<<<****>>>>
  967.           matches every start condition.  Thus, the above example
  968.           could also have been written;
  969.  
  970.               %x example
  971.               %%
  972.               <*>foo   /* do something */
  973.  
  974.  
  975.           The default rule (to EEEECCCCHHHHOOOO any unmatched character) remains
  976.           active in start conditions.
  977.  
  978.           BBBBEEEEGGGGIIIINNNN((((0000)))) returns to the original state where only the rules
  979.           with no start conditions are active.  This state can also be
  980.           referred to as the start-condition "INITIAL", so
  981.           BBBBEEEEGGGGIIIINNNN((((IIIINNNNIIIITTTTIIIIAAAALLLL)))) is equivalent to BBBBEEEEGGGGIIIINNNN((((0000)))).... (The parentheses
  982.           around the start condition name are not required but are
  983.           considered good style.)
  984.  
  985.  
  986.  
  987.      Page 15                                         (printed 3/28/94)
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  995.  
  996.  
  997.  
  998.           BBBBEEEEGGGGIIIINNNN actions can also be given as indented code at the
  999.           beginning of the rules section.  For example, the following
  1000.           will cause the scanner to enter the "SPECIAL" start
  1001.           condition whenever _y_y_l_e_x() is called and the global variable
  1002.           _e_n_t_e_r__s_p_e_c_i_a_l is true:
  1003.  
  1004.                       int enter_special;
  1005.  
  1006.               %x SPECIAL
  1007.               %%
  1008.                       if ( enter_special )
  1009.                           BEGIN(SPECIAL);
  1010.  
  1011.               <SPECIAL>blahblahblah
  1012.               ...more rules follow...
  1013.  
  1014.  
  1015.           To illustrate the uses of start conditions, here is a
  1016.           scanner which provides two different interpretations of a
  1017.           string like "123.456".  By default it will treat it as as
  1018.           three tokens, the integer "123", a dot ('.'), and the
  1019.           integer "456".  But if the string is preceded earlier in the
  1020.           line by the string "expect-floats" it will treat it as a
  1021.           single token, the floating-point number 123.456:
  1022.  
  1023.               %{
  1024.               #include <math.h>
  1025.               %}
  1026.               %s expect
  1027.  
  1028.               %%
  1029.               expect-floats        BEGIN(expect);
  1030.  
  1031.               <expect>[0-9]+"."[0-9]+      {
  1032.                           printf( "found a float, = %f\n",
  1033.                                   atof( yytext ) );
  1034.                           }
  1035.               <expect>\n           {
  1036.                           /* that's the end of the line, so
  1037.                            * we need another "expect-number"
  1038.                            * before we'll recognize any more
  1039.                            * numbers
  1040.                            */
  1041.                           BEGIN(INITIAL);
  1042.                           }
  1043.  
  1044.               [0-9]+      {
  1045.                           printf( "found an integer, = %d\n",
  1046.                                   atoi( yytext ) );
  1047.                           }
  1048.  
  1049.               "."         printf( "found a dot\n" );
  1050.  
  1051.  
  1052.  
  1053.      Page 16                                         (printed 3/28/94)
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  1061.  
  1062.  
  1063.  
  1064.           Here is a scanner which recognizes (and discards) C comments
  1065.           while maintaining a count of the current input line.
  1066.  
  1067.               %x comment
  1068.               %%
  1069.                       int line_num = 1;
  1070.  
  1071.               "/*"         BEGIN(comment);
  1072.  
  1073.               <comment>[^*\n]*        /* eat anything that's not a '*' */
  1074.               <comment>"*"+[^*/\n]*   /* eat up '*'s not followed by '/'s */
  1075.               <comment>\n             ++line_num;
  1076.               <comment>"*"+"/"        BEGIN(INITIAL);
  1077.  
  1078.           This scanner goes to a bit of trouble to match as much text
  1079.           as possible with each rule.  In general, when attempting to
  1080.           write a high-speed scanner try to match as much possible in
  1081.           each rule, as it's a big win.
  1082.  
  1083.           Note that start-conditions names are really integer values
  1084.           and can be stored as such.  Thus, the above could be
  1085.           extended in the following fashion:
  1086.  
  1087.               %x comment foo
  1088.               %%
  1089.                       int line_num = 1;
  1090.                       int comment_caller;
  1091.  
  1092.               "/*"         {
  1093.                            comment_caller = INITIAL;
  1094.                            BEGIN(comment);
  1095.                            }
  1096.  
  1097.               ...
  1098.  
  1099.               <foo>"/*"    {
  1100.                            comment_caller = foo;
  1101.                            BEGIN(comment);
  1102.                            }
  1103.  
  1104.               <comment>[^*\n]*        /* eat anything that's not a '*' */
  1105.               <comment>"*"+[^*/\n]*   /* eat up '*'s not followed by '/'s */
  1106.               <comment>\n             ++line_num;
  1107.               <comment>"*"+"/"        BEGIN(comment_caller);
  1108.  
  1109.           Furthermore, you can access the current start condition
  1110.           using the integer-valued YYYYYYYY____SSSSTTTTAAAARRRRTTTT macro.  For example, the
  1111.           above assignments to _c_o_m_m_e_n_t__c_a_l_l_e_r could instead be written
  1112.  
  1113.               comment_caller = YY_START;
  1114.  
  1115.           Note that start conditions do not have their own name-space;
  1116.  
  1117.  
  1118.  
  1119.      Page 17                                         (printed 3/28/94)
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  1127.  
  1128.  
  1129.  
  1130.           %s's and %x's declare names in the same fashion as
  1131.           #define's.
  1132.  
  1133.           Finally, here's an example of how to match C-style quoted
  1134.           strings using exclusive start conditions, including expanded
  1135.           escape sequences (but not including checking for a string
  1136.           that's too long):
  1137.  
  1138.               %x str
  1139.  
  1140.               %%
  1141.                       char string_buf[MAX_STR_CONST];
  1142.                       char *string_buf_ptr;
  1143.  
  1144.  
  1145.               \"      string_buf_ptr = string_buf; BEGIN(str);
  1146.  
  1147.               <str>\"        { /* saw closing quote - all done */
  1148.                       BEGIN(INITIAL);
  1149.                       *string_buf_ptr = '\0';
  1150.                       /* return string constant token type and
  1151.                        * value to parser
  1152.                        */
  1153.                       }
  1154.  
  1155.               <str>\n        {
  1156.                       /* error - unterminated string constant */
  1157.                       /* generate error message */
  1158.                       }
  1159.  
  1160.               <str>\\[0-7]{1,3} {
  1161.                       /* octal escape sequence */
  1162.                       int result;
  1163.  
  1164.                       (void) sscanf( yytext + 1, "%o", &result );
  1165.  
  1166.                       if ( result > 0xff )
  1167.                               /* error, constant is out-of-bounds */
  1168.  
  1169.                       *string_buf_ptr++ = result;
  1170.                       }
  1171.  
  1172.               <str>\\[0-9]+ {
  1173.                       /* generate error - bad escape sequence; something
  1174.                        * like '\48' or '\0777777'
  1175.                        */
  1176.                       }
  1177.  
  1178.               <str>\\n  *string_buf_ptr++ = '\n';
  1179.               <str>\\t  *string_buf_ptr++ = '\t';
  1180.               <str>\\r  *string_buf_ptr++ = '\r';
  1181.               <str>\\b  *string_buf_ptr++ = '\b';
  1182.  
  1183.  
  1184.  
  1185.      Page 18                                         (printed 3/28/94)
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  1193.  
  1194.  
  1195.  
  1196.               <str>\\f  *string_buf_ptr++ = '\f';
  1197.  
  1198.               <str>\\(.|\n)  *string_buf_ptr++ = yytext[1];
  1199.  
  1200.               <str>[^\\\n\"]+        {
  1201.                       char *yytext_ptr = yytext;
  1202.  
  1203.                       while ( *yytext_ptr )
  1204.                               *string_buf_ptr++ = *yytext_ptr++;
  1205.                       }
  1206.  
  1207.  
  1208.      MMMMUUUULLLLTTTTIIIIPPPPLLLLEEEE IIIINNNNPPPPUUUUTTTT BBBBUUUUFFFFFFFFEEEERRRRSSSS
  1209.           Some scanners (such as those which support "include" files)
  1210.           require reading from several input streams.  As _f_l_e_x
  1211.           scanners do a large amount of buffering, one cannot control
  1212.           where the next input will be read from by simply writing a
  1213.           YYYYYYYY____IIIINNNNPPPPUUUUTTTT which is sensitive to the scanning context.
  1214.           YYYYYYYY____IIIINNNNPPPPUUUUTTTT is only called when the scanner reaches the end of
  1215.           its buffer, which may be a long time after scanning a
  1216.           statement such as an "include" which requires switching the
  1217.           input source.
  1218.  
  1219.           To negotiate these sorts of problems, _f_l_e_x provides a
  1220.           mechanism for creating and switching between multiple input
  1221.           buffers.  An input buffer is created by using:
  1222.  
  1223.               YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
  1224.  
  1225.           which takes a _F_I_L_E pointer and a size and creates a buffer
  1226.           associated with the given file and large enough to hold _s_i_z_e
  1227.           characters (when in doubt, use YYYYYYYY____BBBBUUUUFFFF____SSSSIIIIZZZZEEEE for the size).
  1228.           It returns a YYYYYYYY____BBBBUUUUFFFFFFFFEEEERRRR____SSSSTTTTAAAATTTTEEEE handle, which may then be
  1229.           passed to other routines:
  1230.  
  1231.               void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
  1232.  
  1233.           switches the scanner's input buffer so subsequent tokens
  1234.           will come from _n_e_w__b_u_f_f_e_r. Note that yyyyyyyy____sssswwwwiiiittttcccchhhh____ttttoooo____bbbbuuuuffffffffeeeerrrr(((())))
  1235.           may be used by yywrap() to set things up for continued
  1236.           scanning, instead of opening a new file and pointing _y_y_i_n at
  1237.           it.
  1238.  
  1239.               void yy_delete_buffer( YY_BUFFER_STATE buffer )
  1240.  
  1241.           is used to reclaim the storage associated with a buffer.
  1242.  
  1243.           yyyyyyyy____nnnneeeewwww____bbbbuuuuffffffffeeeerrrr(((()))) is an alias for yyyyyyyy____ccccrrrreeeeaaaatttteeee____bbbbuuuuffffffffeeeerrrr(((()))),,,, provided
  1244.           for compatibility with the C++ use of _n_e_w and _d_e_l_e_t_e for
  1245.           creating and destroying dynamic objects.
  1246.  
  1247.           Finally, the YYYYYYYY____CCCCUUUURRRRRRRREEEENNNNTTTT____BBBBUUUUFFFFFFFFEEEERRRR macro returns a
  1248.  
  1249.  
  1250.  
  1251.      Page 19                                         (printed 3/28/94)
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  1259.  
  1260.  
  1261.  
  1262.           YYYYYYYY____BBBBUUUUFFFFFFFFEEEERRRR____SSSSTTTTAAAATTTTEEEE handle to the current buffer.
  1263.  
  1264.           Here is an example of using these features for writing a
  1265.           scanner which expands include files (the <<<<<<<<EEEEOOOOFFFF>>>>>>>> feature is
  1266.           discussed below):
  1267.  
  1268.               /* the "incl" state is used for picking up the name
  1269.                * of an include file
  1270.                */
  1271.               %x incl
  1272.  
  1273.               %{
  1274.               #define MAX_INCLUDE_DEPTH 10
  1275.               YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
  1276.               int include_stack_ptr = 0;
  1277.               %}
  1278.  
  1279.               %%
  1280.               include             BEGIN(incl);
  1281.  
  1282.               [a-z]+              ECHO;
  1283.               [^a-z\n]*\n?        ECHO;
  1284.  
  1285.               <incl>[ \t]*      /* eat the whitespace */
  1286.               <incl>[^ \t\n]+   { /* got the include file name */
  1287.                       if ( include_stack_ptr >= MAX_INCLUDE_DEPTH )
  1288.                           {
  1289.                           fprintf( stderr, "Includes nested too deeply" );
  1290.                           exit( 1 );
  1291.                           }
  1292.  
  1293.                       include_stack[include_stack_ptr++] =
  1294.                           YY_CURRENT_BUFFER;
  1295.  
  1296.                       yyin = fopen( yytext, "r" );
  1297.  
  1298.                       if ( ! yyin )
  1299.                           error( ... );
  1300.  
  1301.                       yy_switch_to_buffer(
  1302.                           yy_create_buffer( yyin, YY_BUF_SIZE ) );
  1303.  
  1304.                       BEGIN(INITIAL);
  1305.                       }
  1306.  
  1307.               <<EOF>> {
  1308.                       if ( --include_stack_ptr < 0 )
  1309.                           {
  1310.                           yyterminate();
  1311.                           }
  1312.  
  1313.                       else
  1314.  
  1315.  
  1316.  
  1317.      Page 20                                         (printed 3/28/94)
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  1325.  
  1326.  
  1327.  
  1328.                           {
  1329.                           yy_delete_buffer( YY_CURRENT_BUFFER );
  1330.                           yy_switch_to_buffer(
  1331.                                include_stack[include_stack_ptr] );
  1332.                           }
  1333.                       }
  1334.  
  1335.  
  1336.      EEEENNNNDDDD----OOOOFFFF----FFFFIIIILLLLEEEE RRRRUUUULLLLEEEESSSS
  1337.           The special rule "<<EOF>>" indicates actions which are to be
  1338.           taken when an end-of-file is encountered and yywrap()
  1339.           returns non-zero (i.e., indicates no further files to
  1340.           process).  The action must finish by doing one of four
  1341.           things:
  1342.  
  1343.           -    assigning _y_y_i_n to a new input file (in previous
  1344.                versions of flex, after doing the assignment you had to
  1345.                call the special action YYYYYYYY____NNNNEEEEWWWW____FFFFIIIILLLLEEEE;;;; this is no longer
  1346.                necessary);
  1347.  
  1348.           -    executing a _r_e_t_u_r_n statement;
  1349.  
  1350.           -    executing the special yyyyyyyytttteeeerrrrmmmmiiiinnnnaaaatttteeee(((()))) action;
  1351.  
  1352.           -    or, switching to a new buffer using
  1353.                yyyyyyyy____sssswwwwiiiittttcccchhhh____ttttoooo____bbbbuuuuffffffffeeeerrrr(((()))) as shown in the example above.
  1354.  
  1355.           <<EOF>> rules may not be used with other patterns; they may
  1356.           only be qualified with a list of start conditions.  If an
  1357.           unqualified <<EOF>> rule is given, it applies to _a_l_l start
  1358.           conditions which do not already have <<EOF>> actions.  To
  1359.           specify an <<EOF>> rule for only the initial start
  1360.           condition, use
  1361.  
  1362.               <INITIAL><<EOF>>
  1363.  
  1364.  
  1365.           These rules are useful for catching things like unclosed
  1366.           comments.  An example:
  1367.  
  1368.               %x quote
  1369.               %%
  1370.  
  1371.               ...other rules for dealing with quotes...
  1372.  
  1373.               <quote><<EOF>>   {
  1374.                        error( "unterminated quote" );
  1375.                        yyterminate();
  1376.                        }
  1377.               <<EOF>>  {
  1378.                        if ( *++filelist )
  1379.                            yyin = fopen( *filelist, "r" );
  1380.  
  1381.  
  1382.  
  1383.      Page 21                                         (printed 3/28/94)
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  1391.  
  1392.  
  1393.  
  1394.                        else
  1395.                           yyterminate();
  1396.                        }
  1397.  
  1398.  
  1399.      MMMMIIIISSSSCCCCEEEELLLLLLLLAAAANNNNEEEEOOOOUUUUSSSS MMMMAAAACCCCRRRROOOOSSSS
  1400.           The macro YY_USER_ACTION can be defined to provide an action
  1401.           which is always executed prior to the matched rule's action.
  1402.           For example, it could be #define'd to call a routine to
  1403.           convert yytext to lower-case.
  1404.  
  1405.           The macro YYYYYYYY____UUUUSSSSEEEERRRR____IIIINNNNIIIITTTT may be defined to provide an action
  1406.           which is always executed before the first scan (and before
  1407.           the scanner's internal initializations are done).  For
  1408.           example, it could be used to call a routine to read in a
  1409.           data table or open a logging file.
  1410.  
  1411.           In the generated scanner, the actions are all gathered in
  1412.           one large switch statement and separated using YYYYYYYY____BBBBRRRREEEEAAAAKKKK,,,,
  1413.           which may be redefined.  By default, it is simply a "break",
  1414.           to separate each rule's action from the following rule's.
  1415.           Redefining YYYYYYYY____BBBBRRRREEEEAAAAKKKK allows, for example, C++ users to
  1416.           #define YY_BREAK to do nothing (while being very careful
  1417.           that every rule ends with a "break" or a "return"!) to avoid
  1418.           suffering from unreachable statement warnings where because
  1419.           a rule's action ends with "return", the YYYYYYYY____BBBBRRRREEEEAAAAKKKK is
  1420.           inaccessible.
  1421.  
  1422.      IIIINNNNTTTTEEEERRRRFFFFAAAACCCCIIIINNNNGGGG WWWWIIIITTTTHHHH YYYYAAAACCCCCCCC
  1423.           One of the main uses of _f_l_e_x is as a companion to the _y_a_c_c
  1424.           parser-generator.  _y_a_c_c parsers expect to call a routine
  1425.           named yyyyyyyylllleeeexxxx(((()))) to find the next input token.  The routine is
  1426.           supposed to return the type of the next token as well as
  1427.           putting any associated value in the global yyyyyyyyllllvvvvaaaallll.... To use
  1428.           _f_l_e_x with _y_a_c_c, one specifies the ----dddd option to _y_a_c_c to
  1429.           instruct it to generate the file yyyy....ttttaaaabbbb....hhhh containing
  1430.           definitions of all the %%%%ttttooookkkkeeeennnnssss appearing in the _y_a_c_c input.
  1431.           This file is then included in the _f_l_e_x scanner.  For
  1432.           example, if one of the tokens is "TOK_NUMBER", part of the
  1433.           scanner might look like:
  1434.  
  1435.               %{
  1436.               #include "y.tab.h"
  1437.               %}
  1438.  
  1439.               %%
  1440.  
  1441.               [0-9]+        yylval = atoi( yytext ); return TOK_NUMBER;
  1442.  
  1443.  
  1444.      OOOOPPPPTTTTIIIIOOOONNNNSSSS
  1445.           _f_l_e_x has the following options:
  1446.  
  1447.  
  1448.  
  1449.      Page 22                                         (printed 3/28/94)
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  1457.  
  1458.  
  1459.  
  1460.           ----bbbb   Generate backing-up information to _l_e_x._b_a_c_k_u_p. This is
  1461.                a list of scanner states which require backing up and
  1462.                the input characters on which they do so.  By adding
  1463.                rules one can remove backing-up states.  If all
  1464.                backing-up states are eliminated and ----CCCCffff or ----CCCCFFFF is
  1465.                used, the generated scanner will run faster (see the ----pppp
  1466.                flag).  Only users who wish to squeeze every last cycle
  1467.                out of their scanners need worry about this option.
  1468.                (See the section on Performance Considerations below.)
  1469.  
  1470.           ----cccc   is a do-nothing, deprecated option included for POSIX
  1471.                compliance.
  1472.  
  1473.                NNNNOOOOTTTTEEEE:::: in previous releases of _f_l_e_x ----cccc specified table-
  1474.                compression options.  This functionality is now given
  1475.                by the ----CCCC flag.  To ease the the impact of this change,
  1476.                when _f_l_e_x encounters ----cccc,,,, it currently issues a warning
  1477.                message and assumes that ----CCCC was desired instead.  In
  1478.                the future this "promotion" of ----cccc to ----CCCC will go away in
  1479.                the name of full POSIX compliance (unless the POSIX
  1480.                meaning is removed first).
  1481.  
  1482.           ----dddd   makes the generated scanner run in _d_e_b_u_g mode.
  1483.                Whenever a pattern is recognized and the global
  1484.                yyyyyyyy____fffflllleeeexxxx____ddddeeeebbbbuuuugggg is non-zero (which is the default), the
  1485.                scanner will write to _s_t_d_e_r_r a line of the form:
  1486.  
  1487.                    --accepting rule at line 53 ("the matched text")
  1488.  
  1489.                The line number refers to the location of the rule in
  1490.                the file defining the scanner (i.e., the file that was
  1491.                fed to flex).  Messages are also generated when the
  1492.                scanner backs up, accepts the default rule, reaches the
  1493.                end of its input buffer (or encounters a NUL; at this
  1494.                point, the two look the same as far as the scanner's
  1495.                concerned), or reaches an end-of-file.
  1496.  
  1497.           ----ffff   specifies _f_a_s_t _s_c_a_n_n_e_r. No table compression is done
  1498.                and stdio is bypassed.  The result is large but fast.
  1499.                This option is equivalent to ----CCCCffffrrrr (see below).
  1500.  
  1501.           ----hhhh   generates a "help" summary of _f_l_e_x'_s options to _s_t_d_e_r_r
  1502.                and then exits.
  1503.  
  1504.           ----iiii   instructs _f_l_e_x to generate a _c_a_s_e-_i_n_s_e_n_s_i_t_i_v_e scanner.
  1505.                The case of letters given in the _f_l_e_x input patterns
  1506.                will be ignored, and tokens in the input will be
  1507.                matched regardless of case.  The matched text given in
  1508.                _y_y_t_e_x_t will have the preserved case (i.e., it will not
  1509.                be folded).
  1510.  
  1511.           ----llll   turns on maximum compatibility with the original AT&T
  1512.  
  1513.  
  1514.  
  1515.      Page 23                                         (printed 3/28/94)
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  1523.  
  1524.  
  1525.  
  1526.                _l_e_x implementation.  Note that this does not mean _f_u_l_l
  1527.                compatibility.  Use of this option costs a considerable
  1528.                amount of performance, and it cannot be used with the
  1529.                ----++++,,,, ----ffff,,,, ----FFFF,,,, ----CCCCffff,,,, or ----CCCCFFFF options.  For details on the
  1530.                compatibilities it provides, see the section
  1531.                "Incompatibilities With Lex And POSIX" below.
  1532.  
  1533.           ----nnnn   is another do-nothing, deprecated option included only
  1534.                for POSIX compliance.
  1535.  
  1536.           ----pppp   generates a performance report to stderr.  The report
  1537.                consists of comments regarding features of the _f_l_e_x
  1538.                input file which will cause a serious loss of
  1539.                performance in the resulting scanner.  If you give the
  1540.                flag twice, you will also get comments regarding
  1541.                features that lead to minor performance losses.
  1542.  
  1543.                Note that the use of RRRREEEEJJJJEEEECCCCTTTT and variable trailing
  1544.                context (see the Bugs section in flex(1)) entails a
  1545.                substantial performance penalty; use of _y_y_m_o_r_e(), the ^^^^
  1546.                operator, and the ----IIII flag entail minor performance
  1547.                penalties.
  1548.  
  1549.           ----ssss   causes the _d_e_f_a_u_l_t _r_u_l_e (that unmatched scanner input
  1550.                is echoed to _s_t_d_o_u_t) to be suppressed.  If the scanner
  1551.                encounters input that does not match any of its rules,
  1552.                it aborts with an error.  This option is useful for
  1553.                finding holes in a scanner's rule set.
  1554.  
  1555.           ----tttt   instructs _f_l_e_x to write the scanner it generates to
  1556.                standard output instead of lllleeeexxxx....yyyyyyyy....cccc....
  1557.  
  1558.           ----vvvv   specifies that _f_l_e_x should write to _s_t_d_e_r_r a summary of
  1559.                statistics regarding the scanner it generates.  Most of
  1560.                the statistics are meaningless to the casual _f_l_e_x user,
  1561.                but the first line identifies the version of _f_l_e_x (same
  1562.                as reported by ----VVVV)))),,,, and the next line the flags used
  1563.                when generating the scanner, including those that are
  1564.                on by default.
  1565.  
  1566.           ----wwww   suppresses warning messages.
  1567.  
  1568.           ----BBBB   instructs _f_l_e_x to generate a _b_a_t_c_h scanner, the
  1569.                opposite of _i_n_t_e_r_a_c_t_i_v_e scanners generated by ----IIII (see
  1570.                below).  In general, you use ----BBBB when you are _c_e_r_t_a_i_n
  1571.                that your scanner will never be used interactively, and
  1572.                you want to squeeze a _l_i_t_t_l_e more performance out of
  1573.                it.  If your goal is instead to squeeze out a _l_o_t more
  1574.                performance, you should  be using the ----CCCCffff or ----CCCCFFFF
  1575.                options (discussed below), which turn on ----BBBB
  1576.                automatically anyway.
  1577.  
  1578.  
  1579.  
  1580.  
  1581.      Page 24                                         (printed 3/28/94)
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  1589.  
  1590.  
  1591.  
  1592.           ----FFFF   specifies that the _f_a_s_t scanner table representation
  1593.                should be used (and stdio bypassed).  This
  1594.                representation is about as fast as the full table
  1595.                representation ((((----ffff)))),,,, and for some sets of patterns will
  1596.                be considerably smaller (and for others, larger).  In
  1597.                general, if the pattern set contains both "keywords"
  1598.                and a catch-all, "identifier" rule, such as in the set:
  1599.  
  1600.                    "case"    return TOK_CASE;
  1601.                    "switch"  return TOK_SWITCH;
  1602.                    ...
  1603.                    "default" return TOK_DEFAULT;
  1604.                    [a-z]+    return TOK_ID;
  1605.  
  1606.                then you're better off using the full table
  1607.                representation.  If only the "identifier" rule is
  1608.                present and you then use a hash table or some such to
  1609.                detect the keywords, you're better off using ----FFFF....
  1610.  
  1611.                This option is equivalent to ----CCCCFFFFrrrr (see below).  It
  1612.                cannot be used with ----++++....
  1613.  
  1614.           ----IIII   instructs _f_l_e_x to generate an _i_n_t_e_r_a_c_t_i_v_e scanner.  An
  1615.                interactive scanner is one that only looks ahead to
  1616.                decide what token has been matched if it absolutely
  1617.                must.  It turns out that always looking one extra
  1618.                character ahead, even if the scanner has already seen
  1619.                enough text to disambiguate the current token, is a bit
  1620.                faster than only looking ahead when necessary.  But
  1621.                scanners that always look ahead give dreadful
  1622.                interactive performance; for example, when a user types
  1623.                a newline, it is not recognized as a newline token
  1624.                until they enter _a_n_o_t_h_e_r token, which often means
  1625.                typing in another whole line.
  1626.  
  1627.                _F_l_e_x scanners default to _i_n_t_e_r_a_c_t_i_v_e unless you use the
  1628.                ----CCCCffff or ----CCCCFFFF table-compression options (see below).
  1629.                That's because if you're looking for high-performance
  1630.                you should be using one of these options, so if you
  1631.                didn't, _f_l_e_x assumes you'd rather trade off a bit of
  1632.                run-time performance for intuitive interactive
  1633.                behavior.  Note also that you _c_a_n_n_o_t use ----IIII in
  1634.                conjunction with ----CCCCffff or ----CCCCFFFF.... Thus, this option is not
  1635.                really needed; it is on by default for all those cases
  1636.                in which it is allowed.
  1637.  
  1638.                You can force a scanner to _n_o_t be interactive by using
  1639.                ----BBBB (see above).
  1640.  
  1641.           ----LLLL   instructs _f_l_e_x not to generate ####lllliiiinnnneeee directives.
  1642.                Without this option, _f_l_e_x peppers the generated scanner
  1643.                with #line directives so error messages in the actions
  1644.  
  1645.  
  1646.  
  1647.      Page 25                                         (printed 3/28/94)
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  1655.  
  1656.  
  1657.  
  1658.                will be correctly located with respect to the original
  1659.                _f_l_e_x input file, and not to the fairly meaningless line
  1660.                numbers of lllleeeexxxx....yyyyyyyy....cccc.... (Unfortunately _f_l_e_x does not
  1661.                presently generate the necessary directives to
  1662.                "retarget" the line numbers for those parts of lllleeeexxxx....yyyyyyyy....cccc
  1663.                which it generated.  So if there is an error in the
  1664.                generated code, a meaningless line number is reported.)
  1665.  
  1666.           ----TTTT   makes _f_l_e_x run in _t_r_a_c_e mode.  It will generate a lot
  1667.                of messages to _s_t_d_e_r_r concerning the form of the input
  1668.                and the resultant non-deterministic and deterministic
  1669.                finite automata.  This option is mostly for use in
  1670.                maintaining _f_l_e_x.
  1671.  
  1672.           ----VVVV   prints the version number to _s_t_d_e_r_r and exits.
  1673.  
  1674.           ----7777   instructs _f_l_e_x to generate a 7-bit scanner, i.e., one
  1675.                which can only recognized 7-bit characters in its
  1676.                input.  The advantage of using ----7777 is that the scanner's
  1677.                tables can be up to half the size of those generated
  1678.                using the ----8888 option (see below).  The disadvantage is
  1679.                that such scanners often hang or crash if their input
  1680.                contains an 8-bit character.
  1681.  
  1682.                Note, however, that unless you generate your scanner
  1683.                using the ----CCCCffff or ----CCCCFFFF table compression options, use of
  1684.                ----7777 will save only a small amount of table space, and
  1685.                make your scanner considerably less portable.  _F_l_e_x'_s
  1686.                default behavior is to generate an 8-bit scanner unless
  1687.                you use the ----CCCCffff or ----CCCCFFFF,,,, in which case _f_l_e_x defaults to
  1688.                generating 7-bit scanners unless your site was always
  1689.                configured to generate 8-bit scanners (as will often be
  1690.                the case with non-USA sites).  You can tell whether
  1691.                flex generated a 7-bit or an 8-bit scanner by
  1692.                inspecting the flag summary in the ----vvvv output as
  1693.                described above.
  1694.  
  1695.                Note that if you use ----CCCCffffeeee or ----CCCCFFFFeeee (those table
  1696.                compression options, but also using equivalence classes
  1697.                as discussed see below), flex still defaults to
  1698.                generating an 8-bit scanner, since usually with these
  1699.                compression options full 8-bit tables are not much more
  1700.                expensive than 7-bit tables.
  1701.  
  1702.           ----8888   instructs _f_l_e_x to generate an 8-bit scanner, i.e., one
  1703.                which can recognize 8-bit characters.  This flag is
  1704.                only needed for scanners generated using ----CCCCffff or ----CCCCFFFF,,,, as
  1705.                otherwise flex defaults to generating an 8-bit scanner
  1706.                anyway.
  1707.  
  1708.                See the discussion of ----7777 above for flex's default
  1709.                behavior and the tradeoffs between 7-bit and 8-bit
  1710.  
  1711.  
  1712.  
  1713.      Page 26                                         (printed 3/28/94)
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  1721.  
  1722.  
  1723.  
  1724.                scanners.
  1725.  
  1726.           ----++++   specifies that you want flex to generate a C++ scanner
  1727.                class.  See the section on Generating C++ Scanners
  1728.                below for details.
  1729.  
  1730.           ----CCCC[[[[aaaaeeeeffffFFFFmmmmrrrr]]]]
  1731.                controls the degree of table compression and, more
  1732.                generally, trade-offs between small scanners and fast
  1733.                scanners.
  1734.  
  1735.                ----CCCCaaaa ("align") instructs flex to trade off larger tables
  1736.                in the generated scanner for faster performance because
  1737.                the elements of the tables are better aligned for
  1738.                memory access and computation.  On some RISC
  1739.                architectures, fetching and manipulating longwords is
  1740.                more efficient than with smaller-sized datums such as
  1741.                shortwords.  This option can double the size of the
  1742.                tables used by your scanner.
  1743.  
  1744.                ----CCCCeeee directs _f_l_e_x to construct _e_q_u_i_v_a_l_e_n_c_e _c_l_a_s_s_e_s,
  1745.                i.e., sets of characters which have identical lexical
  1746.                properties (for example, if the only appearance of
  1747.                digits in the _f_l_e_x input is in the character class
  1748.                "[0-9]" then the digits '0', '1', ..., '9' will all be
  1749.                put in the same equivalence class).  Equivalence
  1750.                classes usually give dramatic reductions in the final
  1751.                table/object file sizes (typically a factor of 2-5) and
  1752.                are pretty cheap performance-wise (one array look-up
  1753.                per character scanned).
  1754.  
  1755.                ----CCCCffff specifies that the _f_u_l_l scanner tables should be
  1756.                generated - _f_l_e_x should not compress the tables by
  1757.                taking advantages of similar transition functions for
  1758.                different states.
  1759.  
  1760.                ----CCCCFFFF specifies that the alternate fast scanner
  1761.                representation (described above under the ----FFFF flag)
  1762.                should be used.  This option cannot be used with ----++++....
  1763.  
  1764.                ----CCCCmmmm directs _f_l_e_x to construct _m_e_t_a-_e_q_u_i_v_a_l_e_n_c_e _c_l_a_s_s_e_s,
  1765.                which are sets of equivalence classes (or characters,
  1766.                if equivalence classes are not being used) that are
  1767.                commonly used together.  Meta-equivalence classes are
  1768.                often a big win when using compressed tables, but they
  1769.                have a moderate performance impact (one or two "if"
  1770.                tests and one array look-up per character scanned).
  1771.  
  1772.                ----CCCCrrrr causes the generated scanner to _b_y_p_a_s_s use of the
  1773.                standard I/O library (stdio) for input.  Instead of
  1774.                calling ffffrrrreeeeaaaadddd(((()))) or ggggeeeettttcccc(((()))),,,, the scanner will use the
  1775.                rrrreeeeaaaadddd(((()))) system call, resulting in a performance gain
  1776.  
  1777.  
  1778.  
  1779.      Page 27                                         (printed 3/28/94)
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  1787.  
  1788.  
  1789.  
  1790.                which varies from system to system, but in general is
  1791.                probably negligible unless you are also using ----CCCCffff or
  1792.                ----CCCCFFFF.... Using ----CCCCrrrr can cause strange behavior if, for
  1793.                example, you read from _y_y_i_n using stdio prior to
  1794.                calling the scanner (because the scanner will miss
  1795.                whatever text your previous reads left in the stdio
  1796.                input buffer).
  1797.  
  1798.                ----CCCCrrrr has no effect if you define YYYYYYYY____IIIINNNNPPPPUUUUTTTT (see The
  1799.                Generated Scanner above).
  1800.  
  1801.                A lone ----CCCC specifies that the scanner tables should be
  1802.                compressed but neither equivalence classes nor meta-
  1803.                equivalence classes should be used.
  1804.  
  1805.                The options ----CCCCffff or ----CCCCFFFF and ----CCCCmmmm do not make sense
  1806.                together - there is no opportunity for meta-equivalence
  1807.                classes if the table is not being compressed.
  1808.                Otherwise the options may be freely mixed, and are
  1809.                cumulative.
  1810.  
  1811.                The default setting is ----CCCCeeeemmmm,,,, which specifies that _f_l_e_x
  1812.                should generate equivalence classes and meta-
  1813.                equivalence classes.  This setting provides the highest
  1814.                degree of table compression.  You can trade off
  1815.                faster-executing scanners at the cost of larger tables
  1816.                with the following generally being true:
  1817.  
  1818.                    slowest & smallest
  1819.                          -Cem
  1820.                          -Cm
  1821.                          -Ce
  1822.                          -C
  1823.                          -C{f,F}e
  1824.                          -C{f,F}
  1825.                          -C{f,F}a
  1826.                    fastest & largest
  1827.  
  1828.                Note that scanners with the smallest tables are usually
  1829.                generated and compiled the quickest, so during
  1830.                development you will usually want to use the default,
  1831.                maximal compression.
  1832.  
  1833.                ----CCCCffffeeee is often a good compromise between speed and size
  1834.                for production scanners.
  1835.  
  1836.           ----PPPPpppprrrreeeeffffiiiixxxx
  1837.                changes the default _y_y prefix used by _f_l_e_x for all
  1838.                globally-visible variable and function names to instead
  1839.                be _p_r_e_f_i_x. For example, ----PPPPffffoooooooo changes the name of
  1840.                yyyyyyyytttteeeexxxxtttt to ffffooooooootttteeeexxxxtttt.... It also changes the name of the
  1841.                default output file from lllleeeexxxx....yyyyyyyy....cccc to lllleeeexxxx....ffffoooooooo....cccc.... Here
  1842.  
  1843.  
  1844.  
  1845.      Page 28                                         (printed 3/28/94)
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  1853.  
  1854.  
  1855.  
  1856.                are all of the names affected:
  1857.  
  1858.                    yyFlexLexer
  1859.                    yy_create_buffer
  1860.                    yy_delete_buffer
  1861.                    yy_flex_debug
  1862.                    yy_init_buffer
  1863.                    yy_load_buffer_state
  1864.                    yy_switch_to_buffer
  1865.                    yyin
  1866.                    yyleng
  1867.                    yylex
  1868.                    yyout
  1869.                    yyrestart
  1870.                    yytext
  1871.                    yywrap
  1872.  
  1873.                Within your scanner itself, you can still refer to the
  1874.                global variables and functions using either version of
  1875.                their name; but eternally, they have the modified name.
  1876.  
  1877.                This option lets you easily link together multiple _f_l_e_x
  1878.                programs into the same executable.  Note, though, that
  1879.                using this option also renames yyyyyyyywwwwrrrraaaapppp(((()))),,,, so you now
  1880.                _m_u_s_t provide your own (appropriately-named) version of
  1881.                the routine for your scanner, as linking with ----llllffffllll no
  1882.                longer provides one for you by default.
  1883.  
  1884.           ----SSSSsssskkkkeeeelllleeeettttoooonnnn____ffffiiiilllleeee
  1885.                overrides the default skeleton file from which _f_l_e_x
  1886.                constructs its scanners.  You'll never need this option
  1887.                unless you are doing _f_l_e_x maintenance or development.
  1888.  
  1889.      PPPPEEEERRRRFFFFOOOORRRRMMMMAAAANNNNCCCCEEEE CCCCOOOONNNNSSSSIIIIDDDDEEEERRRRAAAATTTTIIIIOOOONNNNSSSS
  1890.           The main design goal of _f_l_e_x is that it generate high-
  1891.           performance scanners.  It has been optimized for dealing
  1892.           well with large sets of rules.  Aside from the effects on
  1893.           scanner speed of the table compression ----CCCC options outlined
  1894.           above, there are a number of options/actions which degrade
  1895.           performance.  These are, from most expensive to least:
  1896.  
  1897.               REJECT
  1898.  
  1899.               pattern sets that require backing up
  1900.               arbitrary trailing context
  1901.  
  1902.               yymore()
  1903.               '^' beginning-of-line operator
  1904.  
  1905.           with the first three all being quite expensive and the last
  1906.           two being quite cheap.  Note also that uuuunnnnppppuuuutttt(((()))) is
  1907.           implemented as a routine call that potentially does quite a
  1908.  
  1909.  
  1910.  
  1911.      Page 29                                         (printed 3/28/94)
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  1919.  
  1920.  
  1921.  
  1922.           bit of work, while yyyyyyyylllleeeessssssss(((()))) is a quite-cheap macro; so if
  1923.           just putting back some excess text you scanned, use
  1924.           yyyyyyyylllleeeessssssss(((())))....
  1925.  
  1926.           RRRREEEEJJJJEEEECCCCTTTT should be avoided at all costs when performance is
  1927.           important.  It is a particularly expensive option.
  1928.  
  1929.           Getting rid of backing up is messy and often may be an
  1930.           enormous amount of work for a complicated scanner.  In
  1931.           principal, one begins by using the ----bbbb flag to generate a
  1932.           _l_e_x._b_a_c_k_u_p file.  For example, on the input
  1933.  
  1934.               %%
  1935.               foo        return TOK_KEYWORD;
  1936.               foobar     return TOK_KEYWORD;
  1937.  
  1938.           the file looks like:
  1939.  
  1940.               State #6 is non-accepting -
  1941.                associated rule line numbers:
  1942.                      2       3
  1943.                out-transitions: [ o ]
  1944.                jam-transitions: EOF [ \001-n  p-\177 ]
  1945.  
  1946.               State #8 is non-accepting -
  1947.                associated rule line numbers:
  1948.                      3
  1949.                out-transitions: [ a ]
  1950.                jam-transitions: EOF [ \001-`  b-\177 ]
  1951.  
  1952.               State #9 is non-accepting -
  1953.                associated rule line numbers:
  1954.                      3
  1955.                out-transitions: [ r ]
  1956.                jam-transitions: EOF [ \001-q  s-\177 ]
  1957.  
  1958.               Compressed tables always back up.
  1959.  
  1960.           The first few lines tell us that there's a scanner state in
  1961.           which it can make a transition on an 'o' but not on any
  1962.           other character, and that in that state the currently
  1963.           scanned text does not match any rule.  The state occurs when
  1964.           trying to match the rules found at lines 2 and 3 in the
  1965.           input file.  If the scanner is in that state and then reads
  1966.           something other than an 'o', it will have to back up to find
  1967.           a rule which is matched.  With a bit of headscratching one
  1968.           can see that this must be the state it's in when it has seen
  1969.           "fo".  When this has happened, if anything other than
  1970.           another 'o' is seen, the scanner will have to back up to
  1971.           simply match the 'f' (by the default rule).
  1972.  
  1973.           The comment regarding State #8 indicates there's a problem
  1974.  
  1975.  
  1976.  
  1977.      Page 30                                         (printed 3/28/94)
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  1985.  
  1986.  
  1987.  
  1988.           when "foob" has been scanned.  Indeed, on any character
  1989.           other than an 'a', the scanner will have to back up to
  1990.           accept "foo".  Similarly, the comment for State #9 concerns
  1991.           when "fooba" has been scanned and an 'r' does not follow.
  1992.  
  1993.           The final comment reminds us that there's no point going to
  1994.           all the trouble of removing backing up from the rules unless
  1995.           we're using ----CCCCffff or ----CCCCFFFF,,,, since there's no performance gain
  1996.           doing so with compressed scanners.
  1997.  
  1998.           The way to remove the backing up is to add "error" rules:
  1999.  
  2000.               %%
  2001.               foo         return TOK_KEYWORD;
  2002.               foobar      return TOK_KEYWORD;
  2003.  
  2004.               fooba       |
  2005.               foob        |
  2006.               fo          {
  2007.                           /* false alarm, not really a keyword */
  2008.                           return TOK_ID;
  2009.                           }
  2010.  
  2011.  
  2012.           Eliminating backing up among a list of keywords can also be
  2013.           done using a "catch-all" rule:
  2014.  
  2015.               %%
  2016.               foo         return TOK_KEYWORD;
  2017.               foobar      return TOK_KEYWORD;
  2018.  
  2019.               [a-z]+      return TOK_ID;
  2020.  
  2021.           This is usually the best solution when appropriate.
  2022.  
  2023.           Backing up messages tend to cascade.  With a complicated set
  2024.           of rules it's not uncommon to get hundreds of messages.  If
  2025.           one can decipher them, though, it often only takes a dozen
  2026.           or so rules to eliminate the backing up (though it's easy to
  2027.           make a mistake and have an error rule accidentally match a
  2028.           valid token.  A possible future _f_l_e_x feature will be to
  2029.           automatically add rules to eliminate backing up).
  2030.  
  2031.           _V_a_r_i_a_b_l_e trailing context (where both the leading and
  2032.           trailing parts do not have a fixed length) entails almost
  2033.           the same performance loss as RRRREEEEJJJJEEEECCCCTTTT (i.e., substantial).  So
  2034.           when possible a rule like:
  2035.  
  2036.               %%
  2037.               mouse|rat/(cat|dog)   run();
  2038.  
  2039.           is better written:
  2040.  
  2041.  
  2042.  
  2043.      Page 31                                         (printed 3/28/94)
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  2051.  
  2052.  
  2053.  
  2054.               %%
  2055.               mouse/cat|dog         run();
  2056.               rat/cat|dog           run();
  2057.  
  2058.           or as
  2059.  
  2060.               %%
  2061.               mouse|rat/cat         run();
  2062.               mouse|rat/dog         run();
  2063.  
  2064.           Note that here the special '|' action does _n_o_t provide any
  2065.           savings, and can even make things worse (see
  2066.  
  2067.           A final note regarding performance: as mentioned above in
  2068.           the section How the Input is Matched, dynamically resizing
  2069.           yyyyyyyytttteeeexxxxtttt to accomodate huge tokens is a slow process because
  2070.           it presently requires that the (huge) token be rescanned
  2071.           from the beginning.  Thus if performance is vital, you
  2072.           should attempt to match "large" quantities of text but not
  2073.           "huge" quantities, where the cutoff between the two is at
  2074.           about 8K characters/token.
  2075.  
  2076.           Another area where the user can increase a scanner's
  2077.           performance (and one that's easier to implement) arises from
  2078.           the fact that the longer the tokens matched, the faster the
  2079.           scanner will run.  This is because with long tokens the
  2080.           processing of most input characters takes place in the
  2081.           (short) inner scanning loop, and does not often have to go
  2082.           through the additional work of setting up the scanning
  2083.           environment (e.g., yyyyyyyytttteeeexxxxtttt)))) for the action.  Recall the
  2084.           scanner for C comments:
  2085.  
  2086.               %x comment
  2087.               %%
  2088.                       int line_num = 1;
  2089.  
  2090.               "/*"         BEGIN(comment);
  2091.  
  2092.               <comment>[^*\n]*
  2093.               <comment>"*"+[^*/\n]*
  2094.               <comment>\n             ++line_num;
  2095.               <comment>"*"+"/"        BEGIN(INITIAL);
  2096.  
  2097.           This could be sped up by writing it as:
  2098.  
  2099.               %x comment
  2100.               %%
  2101.                       int line_num = 1;
  2102.  
  2103.               "/*"         BEGIN(comment);
  2104.  
  2105.               <comment>[^*\n]*
  2106.  
  2107.  
  2108.  
  2109.      Page 32                                         (printed 3/28/94)
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  2117.  
  2118.  
  2119.  
  2120.               <comment>[^*\n]*\n      ++line_num;
  2121.               <comment>"*"+[^*/\n]*
  2122.               <comment>"*"+[^*/\n]*\n ++line_num;
  2123.               <comment>"*"+"/"        BEGIN(INITIAL);
  2124.  
  2125.           Now instead of each newline requiring the processing of
  2126.           another action, recognizing the newlines is "distributed"
  2127.           over the other rules to keep the matched text as long as
  2128.           possible.  Note that _a_d_d_i_n_g rules does _n_o_t slow down the
  2129.           scanner!  The speed of the scanner is independent of the
  2130.           number of rules or (modulo the considerations given at the
  2131.           beginning of this section) how complicated the rules are
  2132.           with regard to operators such as '*' and '|'.
  2133.  
  2134.           A final example in speeding up a scanner: suppose you want
  2135.           to scan through a file containing identifiers and keywords,
  2136.           one per line and with no other extraneous characters, and
  2137.           recognize all the keywords.  A natural first approach is:
  2138.  
  2139.               %%
  2140.               asm      |
  2141.               auto     |
  2142.               break    |
  2143.               ... etc ...
  2144.               volatile |
  2145.               while    /* it's a keyword */
  2146.  
  2147.               .|\n     /* it's not a keyword */
  2148.  
  2149.           To eliminate the back-tracking, introduce a catch-all rule:
  2150.  
  2151.               %%
  2152.               asm      |
  2153.               auto     |
  2154.               break    |
  2155.               ... etc ...
  2156.               volatile |
  2157.               while    /* it's a keyword */
  2158.  
  2159.               [a-z]+   |
  2160.               .|\n     /* it's not a keyword */
  2161.  
  2162.           Now, if it's guaranteed that there's exactly one word per
  2163.           line, then we can reduce the total number of matches by a
  2164.           half by merging in the recognition of newlines with that of
  2165.           the other tokens:
  2166.  
  2167.               %%
  2168.               asm\n    |
  2169.               auto\n   |
  2170.               break\n  |
  2171.               ... etc ...
  2172.  
  2173.  
  2174.  
  2175.      Page 33                                         (printed 3/28/94)
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  2183.  
  2184.  
  2185.  
  2186.               volatile\n |
  2187.               while\n  /* it's a keyword */
  2188.  
  2189.               [a-z]+\n |
  2190.               .|\n     /* it's not a keyword */
  2191.  
  2192.           One has to be careful here, as we have now reintroduced
  2193.           backing up into the scanner.  In particular, while _w_e know
  2194.           that there will never be any characters in the input stream
  2195.           other than letters or newlines, _f_l_e_x can't figure this out,
  2196.           and it will plan for possibly needing to back up when it has
  2197.           scanned a token like "auto" and then the next character is
  2198.           something other than a newline or a letter.  Previously it
  2199.           would then just match the "auto" rule and be done, but now
  2200.           it has no "auto" rule, only a "auto\n" rule.  To eliminate
  2201.           the possibility of backing up, we could either duplicate all
  2202.           rules but without final newlines, or, since we never expect
  2203.           to encounter such an input and therefore don't how it's
  2204.           classified, we can introduce one more catch-all rule, this
  2205.           one which doesn't include a newline:
  2206.  
  2207.               %%
  2208.               asm\n    |
  2209.               auto\n   |
  2210.               break\n  |
  2211.               ... etc ...
  2212.               volatile\n |
  2213.               while\n  /* it's a keyword */
  2214.  
  2215.               [a-z]+\n |
  2216.               [a-z]+   |
  2217.               .|\n     /* it's not a keyword */
  2218.  
  2219.           Compiled with ----CCCCffff,,,, this is about as fast as one can get a
  2220.           _f_l_e_x scanner to go for this particular problem.
  2221.  
  2222.           A final note: _f_l_e_x is slow when matching NUL's, particularly
  2223.           when a token contains multiple NUL's.  It's best to write
  2224.           rules which match _s_h_o_r_t amounts of text if it's anticipated
  2225.           that the text will often include NUL's.
  2226.  
  2227.      GGGGEEEENNNNEEEERRRRAAAATTTTIIIINNNNGGGG CCCC++++++++ SSSSCCCCAAAANNNNNNNNEEEERRRRSSSS
  2228.           _f_l_e_x provides two different ways to generate scanners for
  2229.           use with C++.  The first way is to simply compile a scanner
  2230.           generated by _f_l_e_x using a C++ compiler instead of a C
  2231.           compiler.  You should not encounter any compilations errors
  2232.           (please report any you find to the email address given in
  2233.           the Author section below).  You can then use C++ code in
  2234.           your rule actions instead of C code.  Note that the default
  2235.           input source for your scanner remains _y_y_i_n, and default
  2236.           echoing is still done to _y_y_o_u_t. Both of these remain _F_I_L_E *
  2237.           variables and not C++ _s_t_r_e_a_m_s.
  2238.  
  2239.  
  2240.  
  2241.      Page 34                                         (printed 3/28/94)
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  2249.  
  2250.  
  2251.  
  2252.           You can also use _f_l_e_x to generate a C++ scanner class, using
  2253.           the ----++++ option, which is automatically specified if the name
  2254.           of the flex executable ends in a '+', such as _f_l_e_x++. When
  2255.           using this option, flex defaults to generating the scanner
  2256.           to the file lllleeeexxxx....yyyyyyyy....cccccccc instead of lllleeeexxxx....yyyyyyyy....cccc.... The generated
  2257.           scanner includes the header file _F_l_e_x_L_e_x_e_r._h, which defines
  2258.           the interface to two C++ classes.
  2259.  
  2260.           The first class, FFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr,,,, provides an abstract base class
  2261.           defining the general scanner class interface.  It provides
  2262.           the following member functions:
  2263.  
  2264.           ccccoooonnnnsssstttt cccchhhhaaaarrrr**** YYYYYYYYTTTTeeeexxxxtttt(((())))
  2265.                returns the text of the most recently matched token,
  2266.                the equivalent of yyyyyyyytttteeeexxxxtttt....
  2267.  
  2268.           iiiinnnntttt YYYYYYYYLLLLeeeennnngggg(((())))
  2269.                returns the length of the most recently matched token,
  2270.                the equivalent of yyyyyyyylllleeeennnngggg....
  2271.  
  2272.           Also provided are member functions equivalent to
  2273.           yyyyyyyy____sssswwwwiiiittttcccchhhh____ttttoooo____bbbbuuuuffffffffeeeerrrr(((()))),,,, yyyyyyyy____ccccrrrreeeeaaaatttteeee____bbbbuuuuffffffffeeeerrrr(((()))) (though the first
  2274.           argument is an iiiissssttttrrrreeeeaaaammmm**** object pointer and not a FFFFIIIILLLLEEEE****)))),,,,
  2275.           yyyyyyyy____ddddeeeelllleeeetttteeee____bbbbuuuuffffffffeeeerrrr(((()))),,,, and yyyyyyyyrrrreeeessssttttaaaarrrrtttt(((()))) (again, the first
  2276.           argument is a iiiissssttttrrrreeeeaaaammmm**** object pointer).
  2277.  
  2278.           The second class defined in _F_l_e_x_L_e_x_e_r._h is yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr,,,,
  2279.           which is derived from FFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr.... It defines the following
  2280.           additional member functions:
  2281.  
  2282.           yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr(((( iiiissssttttrrrreeeeaaaammmm**** aaaarrrrgggg____yyyyyyyyiiiinnnn ==== 0000,,,, oooossssttttrrrreeeeaaaammmm**** aaaarrrrgggg____yyyyyyyyoooouuuutttt ==== 0000 ))))
  2283.                constructs a yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr object using the given streams
  2284.                for input and output.  If not specified, the streams
  2285.                default to cccciiiinnnn and ccccoooouuuutttt,,,, respectively.
  2286.  
  2287.           vvvviiiirrrrttttuuuuaaaallll iiiinnnntttt yyyyyyyylllleeeexxxx(((())))
  2288.                performs the same role is yyyyyyyylllleeeexxxx(((()))) does for ordinary
  2289.                flex scanners: it scans the input stream, consuming
  2290.                tokens, until a rule's action returns a value.
  2291.  
  2292.           In addition, yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr defines the following protected
  2293.           virtual functions which you can redefine in derived classes
  2294.           to tailor the scanner:
  2295.  
  2296.           vvvviiiirrrrttttuuuuaaaallll iiiinnnntttt LLLLeeeexxxxeeeerrrrIIIInnnnppppuuuutttt(((( cccchhhhaaaarrrr**** bbbbuuuuffff,,,, iiiinnnntttt mmmmaaaaxxxx____ssssiiiizzzzeeee ))))
  2297.                reads up to mmmmaaaaxxxx____ssssiiiizzzzeeee characters into bbbbuuuuffff and returns
  2298.                the number of characters read.  To indicate end-of-
  2299.                input, return 0 characters.  Note that "interactive"
  2300.                scanners (see the ----BBBB and ----IIII flags) define the macro
  2301.                YYYYYYYY____IIIINNNNTTTTEEEERRRRAAAACCCCTTTTIIIIVVVVEEEE.... If you redefine LLLLeeeexxxxeeeerrrrIIIInnnnppppuuuutttt(((()))) and need
  2302.                to take different actions depending on whether or not
  2303.                the scanner might be scanning an interactive input
  2304.  
  2305.  
  2306.  
  2307.      Page 35                                         (printed 3/28/94)
  2308.  
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  2315.  
  2316.  
  2317.  
  2318.                source, you can test for the presence of this name via
  2319.                ####iiiiffffddddeeeeffff....
  2320.  
  2321.           vvvviiiirrrrttttuuuuaaaallll vvvvooooiiiidddd LLLLeeeexxxxeeeerrrrOOOOuuuuttttppppuuuutttt(((( ccccoooonnnnsssstttt cccchhhhaaaarrrr**** bbbbuuuuffff,,,, iiiinnnntttt ssssiiiizzzzeeee ))))
  2322.                writes out ssssiiiizzzzeeee characters from the buffer bbbbuuuuffff,,,, which,
  2323.                while NUL-terminated, may also contain "internal" NUL's
  2324.                if the scanner's rules can match text with NUL's in
  2325.                them.
  2326.  
  2327.           vvvviiiirrrrttttuuuuaaaallll vvvvooooiiiidddd LLLLeeeexxxxeeeerrrrEEEErrrrrrrroooorrrr(((( ccccoooonnnnsssstttt cccchhhhaaaarrrr**** mmmmssssgggg ))))
  2328.                reports a fatal error message.  The default version of
  2329.                this function writes the message to the stream cccceeeerrrrrrrr and
  2330.                exits.
  2331.  
  2332.           Note that a yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr object contains its _e_n_t_i_r_e scanning
  2333.           state.  Thus you can use such objects to create reentrant
  2334.           scanners.  You can instantiate multiple instances of the
  2335.           same yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr class, and you can also combine multiple
  2336.           C++ scanner classes together in the same program using the
  2337.           ----PPPP option discussed above.
  2338.  
  2339.           Finally, note that the %%%%aaaarrrrrrrraaaayyyy feature is not available to
  2340.           C++ scanner classes; you must use %%%%ppppooooiiiinnnntttteeeerrrr (the default).
  2341.  
  2342.           Here is an example of a simple C++ scanner:
  2343.  
  2344.                   // An example of using the flex C++ scanner class.
  2345.  
  2346.               %{
  2347.               int mylineno = 0;
  2348.               %}
  2349.  
  2350.               string  \"[^\n"]+\"
  2351.  
  2352.               ws      [ \t]+
  2353.  
  2354.               alpha   [A-Za-z]
  2355.               dig     [0-9]
  2356.               name    ({alpha}|{dig}|\$)({alpha}|{dig}|[_.\-/$])*
  2357.               num1    [-+]?{dig}+\.?([eE][-+]?{dig}+)?
  2358.               num2    [-+]?{dig}*\.{dig}+([eE][-+]?{dig}+)?
  2359.               number  {num1}|{num2}
  2360.  
  2361.               %%
  2362.  
  2363.               {ws}    /* skip blanks and tabs */
  2364.  
  2365.               "/*"    {
  2366.                       int c;
  2367.  
  2368.                       while((c = yyinput()) != 0)
  2369.                           {
  2370.  
  2371.  
  2372.  
  2373.      Page 36                                         (printed 3/28/94)
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  2381.  
  2382.  
  2383.  
  2384.                           if(c == '\n')
  2385.                               ++mylineno;
  2386.  
  2387.                           else if(c == '*')
  2388.                               {
  2389.                               if((c = yyinput()) == '/')
  2390.                                   break;
  2391.                               else
  2392.                                   unput(c);
  2393.                               }
  2394.                           }
  2395.                       }
  2396.  
  2397.               {number}  cout << "number " << YYText() << '\n';
  2398.  
  2399.               \n        mylineno++;
  2400.  
  2401.               {name}    cout << "name " << YYText() << '\n';
  2402.  
  2403.               {string}  cout << "string " << YYText() << '\n';
  2404.  
  2405.               %%
  2406.  
  2407.               int main( int /* argc */, char** /* argv */ )
  2408.                   {
  2409.                   FlexLexer* lexer = new yyFlexLexer;
  2410.                   while(lexer->yylex() != 0)
  2411.                       ;
  2412.                   return 0;
  2413.                   }
  2414.           IMPORTANT: the present form of the scanning class is
  2415.           _e_x_p_e_r_i_m_e_n_t_a_l and may change considerably between major
  2416.           releases.
  2417.  
  2418.      IIIINNNNCCCCOOOOMMMMPPPPAAAATTTTIIIIBBBBIIIILLLLIIIITTTTIIIIEEEESSSS WWWWIIIITTTTHHHH LLLLEEEEXXXX AAAANNNNDDDD PPPPOOOOSSSSIIIIXXXX
  2419.           _f_l_e_x is a rewrite of the AT&T Unix _l_e_x tool (the two
  2420.           implementations do not share any code, though), with some
  2421.           extensions and incompatibilities, both of which are of
  2422.           concern to those who wish to write scanners acceptable to
  2423.           either implementation.  The POSIX _l_e_x specification is
  2424.           closer to _f_l_e_x'_s behavior than that of the original _l_e_x
  2425.           implementation, but there also remain some incompatibilities
  2426.           between _f_l_e_x and POSIX.  The intent is that ultimately _f_l_e_x
  2427.           will be fully POSIX-conformant.  In this section we discuss
  2428.           all of the known areas of incompatibility.
  2429.  
  2430.           _f_l_e_x'_s ----llll option turns on maximum compatibility with the
  2431.           original AT&T _l_e_x implementation, at the cost of a major
  2432.           loss in the generated scanner's performance.  We note below
  2433.           which incompatibilities can be overcome using the ----llll option.
  2434.  
  2435.           _f_l_e_x is fully compatible with _l_e_x with the following
  2436.  
  2437.  
  2438.  
  2439.      Page 37                                         (printed 3/28/94)
  2440.  
  2441.  
  2442.  
  2443.  
  2444.  
  2445.  
  2446.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  2447.  
  2448.  
  2449.  
  2450.           exceptions:
  2451.  
  2452.           -    The undocumented _l_e_x scanner internal variable yyyyyyyylllliiiinnnneeeennnnoooo
  2453.                is not supported unless ----llll is used.
  2454.  
  2455.                yylineno is not part of the POSIX specification.
  2456.  
  2457.           -    The iiiinnnnppppuuuutttt(((()))) routine is not redefinable, though it may
  2458.                be called to read characters following whatever has
  2459.                been matched by a rule.  If iiiinnnnppppuuuutttt(((()))) encounters an end-
  2460.                of-file the normal yyyyyyyywwwwrrrraaaapppp(((()))) processing is done.  A
  2461.                ``real'' end-of-file is returned by iiiinnnnppppuuuutttt(((()))) as _E_O_F.
  2462.  
  2463.                Input is instead controlled by defining the YYYYYYYY____IIIINNNNPPPPUUUUTTTT
  2464.                macro.
  2465.  
  2466.                The _f_l_e_x restriction that iiiinnnnppppuuuutttt(((()))) cannot be redefined
  2467.                is in accordance with the POSIX specification, which
  2468.                simply does not specify any way of controlling the
  2469.                scanner's input other than by making an initial
  2470.                assignment to _y_y_i_n.
  2471.  
  2472.           -    _f_l_e_x scanners are not as reentrant as _l_e_x scanners.  In
  2473.                particular, if you have an interactive scanner and an
  2474.                interrupt handler which long-jumps out of the scanner,
  2475.                and the scanner is subsequently called again, you may
  2476.                get the following message:
  2477.  
  2478.                    fatal flex scanner internal error--end of buffer missed
  2479.  
  2480.                To reenter the scanner, first use
  2481.  
  2482.                    yyrestart( yyin );
  2483.  
  2484.                Note that this call will throw away any buffered input;
  2485.                usually this isn't a problem with an interactive
  2486.                scanner.
  2487.  
  2488.                Also note that flex C++ scanner classes _a_r_e reentrant,
  2489.                so if using C++ is an option for you, you should use
  2490.                them instead.  See "Generating C++ Scanners" above for
  2491.                details.
  2492.  
  2493.           -    oooouuuuttttppppuuuutttt(((()))) is not supported.  Output from the EEEECCCCHHHHOOOO macro
  2494.                is done to the file-pointer _y_y_o_u_t (default _s_t_d_o_u_t).
  2495.  
  2496.                oooouuuuttttppppuuuutttt(((()))) is not part of the POSIX specification.
  2497.  
  2498.           -    _l_e_x does not support exclusive start conditions (%x),
  2499.                though they are in the POSIX specification.
  2500.  
  2501.           -    When definitions are expanded, _f_l_e_x encloses them in
  2502.  
  2503.  
  2504.  
  2505.      Page 38                                         (printed 3/28/94)
  2506.  
  2507.  
  2508.  
  2509.  
  2510.  
  2511.  
  2512.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  2513.  
  2514.  
  2515.  
  2516.                parentheses.  With lex, the following:
  2517.  
  2518.                    NAME    [A-Z][A-Z0-9]*
  2519.                    %%
  2520.                    foo{NAME}?      printf( "Found it\n" );
  2521.                    %%
  2522.  
  2523.                will not match the string "foo" because when the macro
  2524.                is expanded the rule is equivalent to "foo[A-Z][A-Z0-
  2525.                9]*?" and the precedence is such that the '?' is
  2526.                associated with "[A-Z0-9]*".  With _f_l_e_x, the rule will
  2527.                be expanded to "foo([A-Z][A-Z0-9]*)?" and so the string
  2528.                "foo" will match.
  2529.  
  2530.                Note that if the definition begins with ^^^^ or ends with
  2531.                $$$$ then it is _n_o_t expanded with parentheses, to allow
  2532.                these operators to appear in definitions without losing
  2533.                their special meanings.  But the <<<<ssss>>>>,,,, ////,,,, and <<<<<<<<EEEEOOOOFFFF>>>>>>>>
  2534.                operators cannot be used in a _f_l_e_x definition.
  2535.  
  2536.                Using ----llll results in the _l_e_x behavior of no parentheses
  2537.                around the definition.
  2538.  
  2539.                The POSIX specification is that the definition be
  2540.                enclosed in parentheses.
  2541.  
  2542.           -    The _l_e_x %%%%rrrr (generate a Ratfor scanner) option is not
  2543.                supported.  It is not part of the POSIX specification.
  2544.  
  2545.           -    After a call to uuuunnnnppppuuuutttt(((()))),,,, _y_y_t_e_x_t and _y_y_l_e_n_g are
  2546.                undefined until the next token is matched, unless the
  2547.                scanner was built using %%%%aaaarrrrrrrraaaayyyy.... This is not the case
  2548.                with _l_e_x or the POSIX specification.  The ----llll option
  2549.                does away with this incompatibility.
  2550.  
  2551.           -    The precedence of the {{{{}}}} (numeric range) operator is
  2552.                different.  _l_e_x interprets "abc{1,3}" as "match one,
  2553.                two, or three occurrences of 'abc'", whereas _f_l_e_x
  2554.                interprets it as "match 'ab' followed by one, two, or
  2555.                three occurrences of 'c'".  The latter is in agreement
  2556.                with the POSIX specification.
  2557.  
  2558.           -    The precedence of the ^^^^ operator is different.  _l_e_x
  2559.                interprets "^foo|bar" as "match either 'foo' at the
  2560.                beginning of a line, or 'bar' anywhere", whereas _f_l_e_x
  2561.                interprets it as "match either 'foo' or 'bar' if they
  2562.                come at the beginning of a line".  The latter is in
  2563.                agreement with the POSIX specification.
  2564.  
  2565.           -    _y_y_i_n is _i_n_i_t_i_a_l_i_z_e_d by _l_e_x to be _s_t_d_i_n; _f_l_e_x, on the
  2566.                other hand, initializes _y_y_i_n to NULL and then _a_s_s_i_g_n_s
  2567.                it to _s_t_d_i_n the first time the scanner is called,
  2568.  
  2569.  
  2570.  
  2571.      Page 39                                         (printed 3/28/94)
  2572.  
  2573.  
  2574.  
  2575.  
  2576.  
  2577.  
  2578.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  2579.  
  2580.  
  2581.  
  2582.                providing _y_y_i_n has not already been assigned to a non-
  2583.                NULL value.  The difference is subtle, but the net
  2584.                effect is that with _f_l_e_x scanners, _y_y_i_n does not have a
  2585.                valid value until the scanner has been called.
  2586.  
  2587.                The ----llll option does away with this incompatibility.
  2588.  
  2589.           -    The special table-size declarations such as %%%%aaaa
  2590.                supported by _l_e_x are not required by _f_l_e_x scanners;
  2591.                _f_l_e_x ignores them.
  2592.  
  2593.           -    The name FLEX_SCANNER is #define'd so scanners may be
  2594.                written for use with either _f_l_e_x or _l_e_x.
  2595.  
  2596.           The following _f_l_e_x features are not included in _l_e_x or the
  2597.           POSIX specification:
  2598.  
  2599.               yyterminate()
  2600.               <<EOF>>
  2601.               <*>
  2602.               YY_DECL
  2603.               YY_START
  2604.               YY_USER_ACTION
  2605.               #line directives
  2606.               %{}'s around actions
  2607.               multiple actions on a line
  2608.  
  2609.           plus almost all of the flex flags.  The last feature in the
  2610.           list refers to the fact that with _f_l_e_x you can put multiple
  2611.           actions on the same line, separated with semi-colons, while
  2612.           with _l_e_x, the following
  2613.  
  2614.               foo    handle_foo(); ++num_foos_seen;
  2615.  
  2616.           is (rather surprisingly) truncated to
  2617.  
  2618.               foo    handle_foo();
  2619.  
  2620.           _f_l_e_x does not truncate the action.  Actions that are not
  2621.           enclosed in braces are simply terminated at the end of the
  2622.           line.
  2623.  
  2624.      DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
  2625.           _w_a_r_n_i_n_g, _r_u_l_e _c_a_n_n_o_t _b_e _m_a_t_c_h_e_d indicates that the given
  2626.           rule cannot be matched because it follows other rules that
  2627.           will always match the same text as it.  For example, in the
  2628.           following "foo" cannot be matched because it comes after an
  2629.           identifier "catch-all" rule:
  2630.  
  2631.               [a-z]+    got_identifier();
  2632.               foo       got_foo();
  2633.  
  2634.  
  2635.  
  2636.  
  2637.      Page 40                                         (printed 3/28/94)
  2638.  
  2639.  
  2640.  
  2641.  
  2642.  
  2643.  
  2644.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  2645.  
  2646.  
  2647.  
  2648.           Using RRRREEEEJJJJEEEECCCCTTTT in a scanner suppresses this warning.
  2649.  
  2650.           _w_a_r_n_i_n_g, ----ssss _o_p_t_i_o_n _g_i_v_e_n _b_u_t _d_e_f_a_u_l_t _r_u_l_e _c_a_n _b_e _m_a_t_c_h_e_d
  2651.           means that it is possible (perhaps only in a particular
  2652.           start condition) that the default rule (match any single
  2653.           character) is the only one that will match a particular
  2654.           input.  Since ----ssss was given, presumably this is not intended.
  2655.  
  2656.           _r_e_j_e_c_t__u_s_e_d__b_u_t__n_o_t__d_e_t_e_c_t_e_d _u_n_d_e_f_i_n_e_d or
  2657.           _y_y_m_o_r_e__u_s_e_d__b_u_t__n_o_t__d_e_t_e_c_t_e_d _u_n_d_e_f_i_n_e_d - These errors can
  2658.           occur at compile time.  They indicate that the scanner uses
  2659.           RRRREEEEJJJJEEEECCCCTTTT or yyyyyyyymmmmoooorrrreeee(((()))) but that _f_l_e_x failed to notice the fact,
  2660.           meaning that _f_l_e_x scanned the first two sections looking for
  2661.           occurrences of these actions and failed to find any, but
  2662.           somehow you snuck some in (via a #include file, for
  2663.           example).  Make an explicit reference to the action in your
  2664.           _f_l_e_x input file.  (Note that previously _f_l_e_x supported a
  2665.           %%%%uuuusssseeeedddd////%%%%uuuunnnnuuuusssseeeedddd mechanism for dealing with this problem; this
  2666.           feature is still supported but now deprecated, and will go
  2667.           away soon unless the author hears from people who can argue
  2668.           compellingly that they need it.)
  2669.  
  2670.           _f_l_e_x _s_c_a_n_n_e_r _j_a_m_m_e_d - a scanner compiled with ----ssss has
  2671.           encountered an input string which wasn't matched by any of
  2672.           its rules.  This error can also occur due to internal
  2673.           problems.
  2674.  
  2675.           _t_o_k_e_n _t_o_o _l_a_r_g_e, _e_x_c_e_e_d_s _Y_Y_L_M_A_X - your scanner uses %%%%aaaarrrrrrrraaaayyyy
  2676.           and one of its rules matched a string longer than the YYYYYYYYLLLLMMMMAAAAXXXX
  2677.           constant (8K bytes by default).  You can increase the value
  2678.           by #define'ing YYYYYYYYLLLLMMMMAAAAXXXX in the definitions section of your
  2679.           _f_l_e_x input.
  2680.  
  2681.           _s_c_a_n_n_e_r _r_e_q_u_i_r_e_s -_8 _f_l_a_g _t_o _u_s_e _t_h_e _c_h_a_r_a_c_t_e_r '_x' - Your
  2682.           scanner specification includes recognizing the 8-bit
  2683.           character '_x' and you did not specify the -8 flag, and your
  2684.           scanner defaulted to 7-bit because you used the ----CCCCffff or ----CCCCFFFF
  2685.           table compression options.  See the discussion of the ----7777
  2686.           flag for details.
  2687.  
  2688.           _f_l_e_x _s_c_a_n_n_e_r _p_u_s_h-_b_a_c_k _o_v_e_r_f_l_o_w - you used uuuunnnnppppuuuutttt(((()))) to push
  2689.           back so much text that the scanner's buffer could not hold
  2690.           both the pushed-back text and the current token in yyyyyyyytttteeeexxxxtttt....
  2691.           Ideally the scanner should dynamically resize the buffer in
  2692.           this case, but at present it does not.
  2693.  
  2694.           _i_n_p_u_t _b_u_f_f_e_r _o_v_e_r_f_l_o_w, _c_a_n'_t _e_n_l_a_r_g_e _b_u_f_f_e_r _b_e_c_a_u_s_e _s_c_a_n_n_e_r
  2695.           _u_s_e_s _R_E_J_E_C_T - the scanner was working on matching an
  2696.           extremely large token and needed to expand the input buffer.
  2697.           This doesn't work with scanners that use RRRREEEEJJJJEEEECCCCTTTT....
  2698.  
  2699.           _f_a_t_a_l _f_l_e_x _s_c_a_n_n_e_r _i_n_t_e_r_n_a_l _e_r_r_o_r--_e_n_d _o_f _b_u_f_f_e_r _m_i_s_s_e_d -
  2700.  
  2701.  
  2702.  
  2703.      Page 41                                         (printed 3/28/94)
  2704.  
  2705.  
  2706.  
  2707.  
  2708.  
  2709.  
  2710.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  2711.  
  2712.  
  2713.  
  2714.           This can occur in an scanner which is reentered after a
  2715.           long-jump has jumped out (or over) the scanner's activation
  2716.           frame.  Before reentering the scanner, use:
  2717.  
  2718.               yyrestart( yyin );
  2719.  
  2720.           or, as noted above, switch to using the C++ scanner class.
  2721.  
  2722.           _t_o_o _m_a_n_y _s_t_a_r_t _c_o_n_d_i_t_i_o_n_s _i_n <> you listed more start
  2723.           conditions in a <> construct than exist (so you must have
  2724.           listed at least one of them twice).
  2725.  
  2726.      FFFFIIIILLLLEEEESSSS
  2727.           See flex(1).
  2728.  
  2729.      DDDDEEEEFFFFIIIICCCCIIIIEEEENNNNCCCCIIIIEEEESSSS //// BBBBUUUUGGGGSSSS
  2730.           Again, see flex(1).
  2731.  
  2732.      SSSSEEEEEEEE AAAALLLLSSSSOOOO
  2733.           flex(1), lex(1), yacc(1), sed(1), awk(1).
  2734.  
  2735.           M. E. Lesk and E. Schmidt, _L_E_X - _L_e_x_i_c_a_l _A_n_a_l_y_z_e_r _G_e_n_e_r_a_t_o_r
  2736.  
  2737.      AAAAUUUUTTTTHHHHOOOORRRR
  2738.           Vern Paxson, with the help of many ideas and much
  2739.           inspiration from Van Jacobson.  Original version by Jef
  2740.           Poskanzer.  The fast table representation is a partial
  2741.           implementation of a design done by Van Jacobson.  The
  2742.           implementation was done by Kevin Gong and Vern Paxson.
  2743.  
  2744.           Thanks to the many _f_l_e_x beta-testers, feedbackers, and
  2745.           contributors, especially Francois Pinard, Casey Leedom,
  2746.           Nelson H.F. Beebe, benson@odi.com, Peter A. Bigot, Keith
  2747.           Bostic, Frederic Brehm, Nick Christopher, Jason Coughlin,
  2748.           Bill Cox, Dave Curtis, Scott David Daniels, Chris G.
  2749.           Demetriou, Mike Donahue, Chuck Doucette, Tom Epperly, Leo
  2750.           Eskin, Chris Faylor, Jon Forrest, Kaveh R. Ghazi, Eric
  2751.           Goldman, Ulrich Grepel, Jan Hajic, Jarkko Hietaniemi, Eric
  2752.           Hughes, John Interrante, Ceriel Jacobs, Jeffrey R. Jones,
  2753.           Henry Juengst, Amir Katz, ken@ken.hilco.com, Kevin B. Kenny,
  2754.           Marq Kole, Ronald Lamprecht, Greg Lee, Craig Leres, John
  2755.           Levine, Steve Liddle, Mohamed el Lozy, Brian Madsen, Chris
  2756.           Metcalf, Luke Mewburn, Jim Meyering, G.T. Nicol, Landon
  2757.           Noll, Marc Nozell, Richard Ohnemus, Sven Panne, Roland
  2758.           Pesch, Walter Pelissero, Gaumond Pierre, Esmond Pitt, Jef
  2759.           Poskanzer, Joe Rahmeh, Frederic Raimbault, Rick Richardson,
  2760.           Kevin Rodgers, Jim Roskind, Doug Schmidt, Philippe
  2761.           Schnoebelen, Andreas Schwab, Alex Siegel, Mike Stump, Paul
  2762.           Stuart, Dave Tallman, Chris Thewalt, Paul Tuinenga, Gary
  2763.           Weik, Frank Whaley, Gerhard Wilhelms, Kent Williams, Ken
  2764.           Yap, Nathan Zelle, David Zuhn, and those whose names have
  2765.           slipped my marginal mail-archiving skills but whose
  2766.  
  2767.  
  2768.  
  2769.      Page 42                                         (printed 3/28/94)
  2770.  
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.      FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....4444 ((((NNNNoooovvvveeeemmmmbbbbeeeerrrr 1111999999993333))))         FFFFLLLLEEEEXXXXDDDDOOOOCCCC((((1111))))
  2777.  
  2778.  
  2779.  
  2780.           contributions are appreciated all the same.
  2781.  
  2782.           Thanks to Keith Bostic, Jon Forrest, Noah Friedman, John
  2783.           Gilmore, Craig Leres, John Levine, Bob Mulcahy, G.T.  Nicol,
  2784.           Francois Pinard, Rich Salz, and Richard Stallman for help
  2785.           with various distribution headaches.
  2786.  
  2787.           Thanks to Esmond Pitt and Earle Horton for 8-bit character
  2788.           support; to Benson Margulies and Fred Burke for C++ support;
  2789.           to Kent Williams and Tom Epperly for C++ class support; to
  2790.           Ove Ewerlid for support of NUL's; and to Eric Hughes for
  2791.           support of multiple buffers.
  2792.  
  2793.           This work was primarily done when I was with the Real Time
  2794.           Systems Group at the Lawrence Berkeley Laboratory in
  2795.           Berkeley, CA.  Many thanks to all there for the support I
  2796.           received.
  2797.  
  2798.           Send comments to:
  2799.  
  2800.                Vern Paxson
  2801.                Systems Engineering
  2802.                Bldg. 46A, Room 1123
  2803.                Lawrence Berkeley Laboratory
  2804.                University of California
  2805.                Berkeley, CA 94720
  2806.  
  2807.                vern@ee.lbl.gov
  2808.  
  2809.  
  2810.  
  2811.  
  2812.  
  2813.  
  2814.  
  2815.  
  2816.  
  2817.  
  2818.  
  2819.  
  2820.  
  2821.  
  2822.  
  2823.  
  2824.  
  2825.  
  2826.  
  2827.  
  2828.  
  2829.  
  2830.  
  2831.  
  2832.  
  2833.  
  2834.  
  2835.      Page 43                                         (printed 3/28/94)
  2836.  
  2837.  
  2838.  
  2839.